Advertisement
Lyubohd

04. Cruise Games

Feb 22nd, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem04 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String playerName = scan.nextLine();
  8.         int playedGames = Integer.parseInt(scan.nextLine());
  9.  
  10.         int volleyballCounter = 0;
  11.         double volleyballPoints = 0.0;
  12.  
  13.         int tennisCounter = 0;
  14.         double tennisPoints = 0.0;
  15.  
  16.         int badmintonCounter = 0;
  17.         double badmintonPoints = 0.0;
  18.  
  19.         for (int i = 0; i < playedGames; i++) {
  20.             String game = scan.nextLine();
  21.             int points = Integer.parseInt(scan.nextLine());
  22.  
  23.             switch (game) {
  24.                 case "volleyball":
  25.                     volleyballCounter++;
  26.                     volleyballPoints += points * 1.07;
  27.                     break;
  28.                 case "tennis":
  29.                     tennisCounter++;
  30.                     tennisPoints += points * 1.05;
  31.                     break;
  32.                 case "badminton":
  33.                     badmintonCounter++;
  34.                     badmintonPoints += points * 1.02;
  35.                     break;
  36.             }
  37.         }
  38.  
  39.         double volleyballAvg = volleyballPoints / volleyballCounter;
  40.         double tennisAvg = tennisPoints / tennisCounter;
  41.         double badmintonAvg = badmintonPoints / badmintonCounter;
  42.  
  43.         double sum = Math.floor(volleyballPoints + tennisPoints + badmintonPoints);
  44.  
  45.         if (volleyballAvg >= 75 && tennisAvg >= 75 && badmintonAvg >= 75) {
  46.             System.out.printf("Congratulations, %s! You won the cruise games with %.0f points.", playerName, sum);
  47.         } else {
  48.             System.out.printf("Sorry, %s, you lost. Your points are only %.0f.", playerName, sum);
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement