Advertisement
SotirovG

basketball_05

Oct 23rd, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. package ExamPractice;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class BasketballTournaments_06 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String tournament = scanner.nextLine();
  9.  
  10.         int ownPoints = 0;
  11.         int gainPoints = 0;
  12.         int gamesCounter = 0;
  13.         int totalWonGames = 0;
  14.         int totalLostGames = 0;
  15.  
  16.         while (!tournament.equals("End of tournaments")) {
  17.  
  18.             int numGames = Integer.parseInt(scanner.nextLine());
  19.             gamesCounter += numGames;
  20.  
  21.  
  22.  
  23.             for (int i = 1; i <= numGames; i++) {
  24.  
  25.                 int pointsOwn = Integer.parseInt(scanner.nextLine());
  26.                 int pointsGain = Integer.parseInt(scanner.nextLine());
  27.  
  28.                 if (pointsGain > pointsOwn) {
  29.                     totalLostGames++;
  30.  
  31.                     gainPoints = pointsGain - pointsOwn;
  32.                     System.out.printf("Game %d of tournament %s: lost with %d points.%n",i,tournament, gainPoints);
  33.  
  34.                 } else {
  35.                     totalWonGames++;
  36.  
  37.                     ownPoints = pointsOwn - pointsGain;
  38.                     System.out.printf("Game %d of tournament %s: win with %d points.%n", i,tournament, ownPoints);
  39.  
  40.                 }
  41.  
  42.             }
  43.  
  44.  
  45.             tournament = scanner.nextLine();
  46.         }
  47.  
  48.  
  49.  
  50.         double wonGamesPercent = 1.0 * totalWonGames / gamesCounter * 100;
  51.         double lostGamesPercent = 1.0 * totalLostGames / gamesCounter * 100;
  52.         System.out.printf("%.2f%% matches win", wonGamesPercent);
  53.         System.out.printf("%.2f%% matches lost", lostGamesPercent);
  54.  
  55.  
  56.  
  57.     }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement