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