Advertisement
Ligh7_of_H3av3n

Tax Calculator

Feb 18th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package Izpit;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Pomosht {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.  
  11.         String vehiclesInput = scanner.nextLine();
  12.         String[] vehicles = vehiclesInput.split(">>");
  13.  
  14.        
  15.         double totalTaxCollected = 0;
  16.  
  17.        
  18.         for (String vehicle : vehicles) {
  19.            
  20.             String[] vehicleInfo = vehicle.split("\\s+");
  21.             String type = vehicleInfo[0];
  22.             int years = Integer.parseInt(vehicleInfo[1]);
  23.             int kilometers = Integer.parseInt(vehicleInfo[2]);
  24.  
  25.            
  26.             double tax = calculateTax(type, years, kilometers);
  27.  
  28.          
  29.             tax = Math.max(0, tax);
  30.  
  31.            
  32.             totalTaxCollected += tax;
  33.  
  34.            
  35.             System.out.printf("A %s car will pay %.2f euros in taxes.%n", type, tax);
  36.         }
  37.  
  38.        
  39.         System.out.printf("The National Revenue Agency will collect %.2f euros in taxes.", totalTaxCollected);
  40.     }
  41.  
  42.    
  43.     private static double calculateTax(String type, int years, int kilometers) {
  44.         switch (type) {
  45.             case "family":
  46.                 return 50 - (years * 5) + (kilometers / 3000) * 12;
  47.             case "heavyDuty":
  48.                 return 80 - (years * 8) + (kilometers / 9000) * 14;
  49.             case "sports":
  50.                 return 100 - (years * 9) + (kilometers / 2000) * 18;
  51.             default:
  52.                
  53.                 System.out.println("Invalid car type.");
  54.                 return 0;
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement