Advertisement
yovkovbpfps

EXAM 28-29 JULY 2018 04.Group Stage

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