desislava_topuzakova

05. Football Tournament

Jul 17th, 2021
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FootballTournament_04 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String teamName = scanner.nextLine();
  7.         int countMatches = Integer.parseInt(scanner.nextLine());
  8.  
  9.         if (countMatches == 0) {
  10.             System.out.printf("%s hasn't played any games during this season.", teamName);
  11.         } else {
  12.             int totalPoints = 0; //брой спечелени точки
  13.             int countWins = 0;  //брой победи
  14.             int countDraws = 0; //брой равенства
  15.             int countLoses = 0; //брой загуби
  16.             for (int match = 1; match <= countMatches; match++) {
  17.                 String result = scanner.nextLine(); // "W", "D" и "L"
  18.                 switch(result) {
  19.                     case "W":
  20.                         totalPoints += 3;
  21.                         countWins++;
  22.                         break;
  23.                     case "D":
  24.                         totalPoints += 1;
  25.                         countDraws++;
  26.                         break;
  27.                     case "L":
  28.                         countLoses++;
  29.                         break;
  30.                 }
  31.             }
  32.             System.out.printf("%s has won %d points during this season.%n",teamName , totalPoints);
  33.             System.out.println("Total stats:");
  34.             System.out.printf("## W: %d%n", countWins);
  35.             System.out.printf("## D: %d%n", countDraws);
  36.             System.out.printf("## L: %d%n", countLoses);
  37.             double percentWins = countWins * 1.0 / countMatches * 100;
  38.             System.out.printf("Win rate: %.2f%%", percentWins);
  39.  
  40.         }
  41.  
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment