Advertisement
desislava_topuzakova

05. Cruise Games

Jun 6th, 2020
1,654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String playerName = scanner.nextLine();
  7.         int countPlays = Integer.parseInt(scanner.nextLine());
  8.         int countVolleyball = 0;
  9.         int countTennis = 0;
  10.         int countBadminton = 0;
  11.         double pointsVolleyball = 0;
  12.         double pointsTennis = 0;
  13.         double pointsBadminton = 0;
  14.         for (int games = 1; games <= countPlays; games++) {
  15.             String gameName = scanner.nextLine(); //"volleyball", "tennis", "badminton"
  16.             int points = Integer.parseInt(scanner.nextLine());
  17.             //за всеки спорт -> средно аритметичното (пъти + общ брой точки)
  18.             if (gameName.equals("volleyball")) {
  19.                 countVolleyball++;
  20.                 //7% бонус
  21.                 pointsVolleyball += points + 0.07 * points;
  22.             } else if (gameName.equals("tennis")) {
  23.                 countTennis++;
  24.                 pointsTennis += points + 0.05 * points;
  25.             } else if (gameName.equals("badminton")) {
  26.                 countBadminton++;
  27.                 pointsBadminton += points + 0.02 * points;
  28.             }
  29.  
  30.         }
  31.         //за всеки спорт -> колко пъти е игран и колко общо точки имаме от него
  32.         //средно аритм = сум от точките / бр. пъти
  33.         double averageVolleyball = pointsVolleyball / countVolleyball;
  34.         double averageTennis = pointsTennis / countTennis;
  35.         double averageBadminton = pointsBadminton / countBadminton;
  36.  
  37.         double totalPoints = Math.floor(pointsVolleyball + pointsBadminton + pointsTennis);
  38.         //печелим
  39.         if (averageVolleyball >= 75 && averageTennis >= 75 && averageBadminton >= 75){
  40.             System.out.printf("Congratulations, %s! You won the cruise games with %.0f points.", playerName, totalPoints);
  41.         } else {
  42.             System.out.printf("Sorry, %s, you lost. Your points are only %.0f.", playerName, totalPoints);
  43.         }
  44.  
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement