Advertisement
Ligh7_of_H3av3n

FixedCode_Tax_Calcilator

Feb 18th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TaskTwoOfThree {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String command = scanner.nextLine();
  7.         String[] vehicles = command.split(">>");
  8.         double agencyCollected = 0;
  9.  
  10.         for (String car : vehicles) {
  11.             String[] features = car.split(" ");
  12.             String carType = features[0];
  13.             int yearsOfCar = Integer.parseInt(features[1]);
  14.             double travelKm = Double.parseDouble(features[2]);
  15.  
  16.             double tax = 0;
  17.             switch (carType) {
  18.                 case "family":
  19.                     tax = 50 - yearsOfCar * 5 + (travelKm / 3000) * 12;
  20.                     System.out.printf("A %s car will pay %.2f euros in taxes.%n", carType, tax);
  21.                     break;
  22.                 case "heavyDuty":
  23.                     tax = 80 - yearsOfCar * 8 + (travelKm / 9000) * 14;
  24.                     System.out.printf("A %s car will pay %.2f euros in taxes.%n", carType, tax);
  25.                     break;
  26.                 case "sports":
  27.                     tax = 100 - yearsOfCar * 9 + (travelKm / 2000) * 18;
  28.                     System.out.printf("A %s car will pay %.2f euros in taxes.%n", carType, tax);
  29.                     break;
  30.                 default:
  31.                     System.out.println("Invalid car type.");
  32.                     continue;
  33.             }
  34.             agencyCollected += tax;
  35.         }
  36.         System.out.printf("The National Revenue Agency will collect %.2f euros in taxes.", agencyCollected);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement