Advertisement
Spocoman

02. Bike Race

Aug 26th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BikeRace {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int juniorCount = Integer.parseInt(scanner.nextLine());
  7.         int seniorCount = Integer.parseInt(scanner.nextLine());
  8.         String trace = scanner.nextLine();
  9.  
  10.         double juniorPrice = 0, seniorPrice = 0;
  11.  
  12.         switch (trace) {
  13.             case "trail" -> {
  14.                 juniorPrice = 5.50;
  15.                 seniorPrice = 7.00;
  16.             }
  17.             case "cross-country" -> {
  18.                 juniorPrice = 8.00;
  19.                 seniorPrice = 9.50;
  20.             }
  21.             case "downhill" -> {
  22.                 juniorPrice = 12.25;
  23.                 seniorPrice = 13.75;
  24.             }
  25.             case "road" -> {
  26.                 juniorPrice = 20.00;
  27.                 seniorPrice = 21.50;
  28.             }
  29.         }
  30.  
  31.         double sum = juniorPrice * juniorCount + seniorPrice * seniorCount;
  32.  
  33.         if (trace.equals("cross-country") && juniorCount + seniorCount >= 50) {
  34.             sum *= 0.75;
  35.         }
  36.  
  37.         System.out.printf("%.2f\n", sum * 0.95);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement