Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam;
- import java.util.Scanner;
- public class TaxCalculator {
- 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 vehicleData : vehicles) {
- String[] vehicleInfo = vehicleData.split("\\s+");
- String type = vehicleInfo[0];
- int years = Integer.parseInt(vehicleInfo[1]);
- int kilometers = Integer.parseInt(vehicleInfo[2]);
- double tax = calculateTax(type, years, kilometers);
- if (tax >= 0) {
- System.out.printf("A %s car will pay %.2f euros in taxes.%n", type, tax);
- totalTaxCollected += tax;
- } else {
- System.out.println("Invalid car type.");
- }
- }
- 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 Math.max(0, 50 - (years * 5) + (kilometers / 3000) * 12);
- case "heavyDuty":
- return Math.max(0, 80 - (years * 8) + (kilometers / 9000) * 14);
- case "sports":
- return Math.max(0, 100 - (years * 9) + (kilometers / 2000) * 18);
- default:
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement