Advertisement
Ligh7_of_H3av3n

FixedCode_Tax_Calcilator

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