Advertisement
veronikaaa86

06. Basketball Tournament

Apr 22nd, 2023
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P06BasketballTournament {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int totalGamesCount = 0;
  10.         int winGamesCount = 0;
  11.         int lostGamesCount = 0;
  12.         String input = scanner.nextLine();
  13.         while (!input.equals("End of tournaments")) {
  14.             String tournamentName = input;
  15.             int gamesCount = Integer.parseInt(scanner.nextLine());
  16.  
  17.             for (int i = 1; i <= gamesCount; i++) {
  18.                 totalGamesCount++;
  19.  
  20.                 int desiTeamPoints = Integer.parseInt(scanner.nextLine());
  21.                 int otherTeamPoints = Integer.parseInt(scanner.nextLine());
  22.  
  23.                 int diff = Math.abs(desiTeamPoints - otherTeamPoints);
  24.  
  25.                 if (desiTeamPoints > otherTeamPoints) {
  26.                     winGamesCount++;
  27.                     System.out.printf("Game %d of tournament %s: win with %d points.%n", i, tournamentName, diff);
  28.                 } else {
  29.                     lostGamesCount++;
  30.                     System.out.printf("Game %d of tournament %s: lost with %d points.%n", i, tournamentName, diff);
  31.                 }
  32.             }
  33.  
  34.             input = scanner.nextLine();
  35.         }
  36.  
  37.         double percentWin = winGamesCount * 1.0 / totalGamesCount * 100;
  38.         System.out.printf("%.2f%% matches win%n", percentWin);
  39.         double percentLost = lostGamesCount * 1.0 / totalGamesCount * 100;
  40.         System.out.printf("%.2f%% matches lost%n", percentLost);
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement