Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Izpit;
- import java.util.Scanner;
- public class Pomosht {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String vehiclesInput = scanner.nextLine();
- String[] vehicles = vehiclesInput.split(">>");
- double totalTaxCollected = 0;
- for (String vehicle : vehicles) {
- String[] vehicleInfo = vehicle.split("\\s+");
- String type = vehicleInfo[0];
- int years = Integer.parseInt(vehicleInfo[1]);
- int kilometers = Integer.parseInt(vehicleInfo[2]);
- double tax = calculateTax(type, years, kilometers);
- tax = Math.max(0, tax);
- totalTaxCollected += tax;
- System.out.printf("A %s car will pay %.2f euros in taxes.%n", type, tax);
- }
- System.out.printf("The National Revenue Agency will collect %.2f euros in taxes.", totalTaxCollected);
- }
- private static double calculateTax(String type, int years, int kilometers) {
- switch (type) {
- case "family":
- return 50 - (years * 5) + (kilometers / 3000) * 12;
- case "heavyDuty":
- return 80 - (years * 8) + (kilometers / 9000) * 14;
- case "sports":
- return 100 - (years * 9) + (kilometers / 2000) * 18;
- default:
- System.out.println("Invalid car type.");
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement