Advertisement
todor_boichev

Untitled

Oct 20th, 2020
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. package Exams07072019;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FootballTournament {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String name = scanner.nextLine();
  9.         int number = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int wCounter = 0;
  12.         int dCounter = 0;
  13.         int lCounter = 0;
  14.         int totalPoints = 0;
  15.  
  16.         for (int i = 1; i <= number; i++) {
  17.             String result = scanner.nextLine();
  18.  
  19.             if (result.equals("W")) {
  20.                 wCounter++;
  21.                 totalPoints = totalPoints + 3;
  22.             } else if (result.equals("D")) {
  23.                 dCounter++;
  24.                 totalPoints = totalPoints + 1;
  25.             } else {
  26.                 lCounter++;
  27.             }
  28.         }
  29.  
  30.         double winGames = 1.0 * wCounter / (wCounter + dCounter + lCounter) * 100;
  31.  
  32.         if (number > 0) {
  33.             System.out.printf("%s has won %d points during this season.\n", name, totalPoints);
  34.             System.out.println("Total stats:");
  35.             System.out.printf("## W: %d\n", wCounter);
  36.             System.out.printf("## D: %d\n", dCounter);
  37.             System.out.printf("## L: %d\n", lCounter);
  38.             System.out.printf("Win rate: %.2f%%", winGames);
  39.         } else {
  40.             System.out.println("Chelsea hasn't played any games during this season.");
  41.         }
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement