Advertisement
SensaBG

BasktetBall Tournament

Jul 1st, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BasktetBallTournamentExam1 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String command = scanner.nextLine();
  8.         int totalMatches = 0;
  9.         int wins = 0;
  10.  
  11.         while (!"End of tournaments".equals(command)) {
  12.             String teamName = command;
  13.             int matchesAmount = Integer.parseInt(scanner.nextLine());
  14.  
  15.             for (int i = 1; i <= matchesAmount; i++) {
  16.                 int teamDesiPoints = Integer.parseInt(scanner.nextLine());
  17.                 int enemyTeamPoints = Integer.parseInt(scanner.nextLine());
  18.  
  19.                 boolean isWinner = teamDesiPoints > enemyTeamPoints;
  20.  
  21.                 if (isWinner) {
  22.                     System.out.printf("Game %d of tournament %s: win with %d points.\n", i, teamName, teamDesiPoints - enemyTeamPoints);
  23.                     wins++;
  24.                 } else {
  25.                     System.out.printf("Game %d of tournament %s: lost with %d points.\n", i, teamName, Math.abs(teamDesiPoints - enemyTeamPoints));
  26.                 }
  27.                 totalMatches++;
  28.             }
  29.             command = scanner.nextLine();
  30.         }
  31.  
  32.         int defeats = totalMatches - wins;
  33.  
  34.         double winRate = (wins * 100.0) / totalMatches;
  35.         double loseRate = (defeats * 100.0) / totalMatches;
  36.  
  37.         System.out.printf("%.2f%% matches win\n", winRate);
  38.         System.out.printf("%.2f%% matches lost\n", loseRate);
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement