SophiYo

GroupStage

Dec 19th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. package July2018Exam;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class O4GroupStage {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String teamName = scanner.nextLine();
  9.         int games = Integer.parseInt(scanner.nextLine());
  10.         int countGames = 0;
  11.         int points = 0;
  12.         int totalTGoals = 0;
  13.         int totalCompGoals = 0;
  14.         int diffOnGame = 0;
  15.         int totalDifference = 0;
  16.  
  17.  
  18.         while (countGames != games) {
  19.             int teamGoals = Integer.parseInt(scanner.nextLine());
  20.             int competitorGoals = Integer.parseInt(scanner.nextLine());
  21.             countGames++;
  22.             diffOnGame = teamGoals - competitorGoals;
  23.  
  24.             if (teamGoals > competitorGoals ) {
  25.                 points += 3;
  26.                 totalTGoals += teamGoals;
  27.                 totalCompGoals += competitorGoals;
  28.  
  29.  
  30.             }
  31.              if (teamGoals == competitorGoals ) {
  32.                  points += 1;
  33.                  totalTGoals += teamGoals;
  34.                  totalCompGoals += competitorGoals;
  35.                               }
  36.              if (teamGoals < competitorGoals) {
  37.                  points += 0;
  38.                  totalTGoals += teamGoals;
  39.                  totalCompGoals += competitorGoals;
  40.              }
  41.  
  42.              totalDifference += diffOnGame;
  43.         }
  44.  
  45.         if (totalTGoals >= totalCompGoals) {
  46.             System.out.printf("%s has finished the group phase with %d points.%n", teamName, points);
  47.             System.out.printf("Goal difference: %d.", totalDifference);
  48.         } else {
  49.             System.out.printf("%s has been eliminated from the group phase.%n", teamName);
  50.             System.out.printf("Goal difference: %d.", totalDifference);
  51.         }
  52.  
  53.  
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment