Advertisement
veronikaaa86

05. Fitness Center

Feb 18th, 2023
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04FitnessCenter {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int backCount = 0;
  10.         int chestCount = 0;
  11.         int legsCount = 0;
  12.         int absCount = 0;
  13.         int proteinShakeCount = 0;
  14.         int proteinBarCount = 0;
  15.  
  16.         int people = Integer.parseInt(scanner.nextLine());
  17.         for (int i = 1; i <= people; i++) {
  18.             String action = scanner.nextLine();
  19.  
  20.             switch (action) {
  21.                 case "Back":
  22.                     backCount++;
  23.                     break;
  24.                 case "Chest":
  25.                     chestCount++;
  26.                     break;
  27.                 case "Legs":
  28.                     legsCount++;
  29.                     break;
  30.                 case "Abs":
  31.                     absCount++;
  32.                     break;
  33.                 case "Protein shake":
  34.                     proteinShakeCount++;
  35.                     break;
  36.                 case "Protein bar":
  37.                     proteinBarCount++;
  38.                     break;
  39.             }
  40.         }
  41.  
  42.         System.out.printf("%d - back%n", backCount);
  43.         System.out.printf("%d - chest%n", chestCount);
  44.         System.out.printf("%d - legs%n", legsCount);
  45.         System.out.printf("%d - abs%n", absCount);
  46.         System.out.printf("%d - protein shake%n", proteinShakeCount);
  47.         System.out.printf("%d - protein bar%n", proteinBarCount);
  48.  
  49.         int sumWorkout = backCount + chestCount + legsCount + absCount;
  50.         System.out.printf("%.2f%% - work out%n", sumWorkout * 1.0 / people * 100);
  51.         int sumProtein = proteinBarCount + proteinShakeCount;
  52.         System.out.printf("%.2f%% - protein%n", sumProtein * 1.0 / people * 100);
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement