Advertisement
Spocoman

06. Truck Driver

Aug 26th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TruckDriver {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String season = scanner.nextLine();
  7.         double km = Double.parseDouble(scanner.nextLine());
  8.  
  9.         double kmPrice = 0;
  10.  
  11.         if (km > 0 && km <= 5000) {
  12.             kmPrice = switch (season) {
  13.                 case "Spring", "Autumn" -> 0.75;
  14.                 case "Summer" -> 0.90;
  15.                 case "Winter" -> 1.05;
  16.                 default -> kmPrice;
  17.             };
  18.         } else if (km > 5000 && km <= 10000) {
  19.             kmPrice = switch (season) {
  20.                 case "Spring", "Autumn" -> 0.95;
  21.                 case "Summer" -> 1.10;
  22.                 case "Winter" -> 1.25;
  23.                 default -> kmPrice;
  24.             };
  25.         } else if (km > 10000 && km <= 20000) {
  26.             kmPrice = 1.45;
  27.         }
  28.  
  29.         System.out.printf("%.2f\n", kmPrice * km * 4 * 0.90);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement