Advertisement
Valantina

CruiseGames/Ex/27.07.2019/Java

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