KnowledgeBoat Logo

Computer Applications

In order to purchase an old car, the depreciated value can be calculated as per the tariff given below:

No. of years usedRate of depreciation
110%
220%
330%
450%
Above 4 years60%

Write a menu driven program to input showroom price and the number of years the car is used ('1' for one year old, '2' for two years old and so on). Calculate the depreciated value. Display the original price of the car, depreciated value and the amount to be paid.

Java

Java Conditional Stmts

57 Likes

Answer

import java.util.Scanner;

public class KboatCarValue
{
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        
        System.out.println("1. One year old car");
        System.out.println("2. Two year old car");
        System.out.println("3. Three year old car");
        System.out.println("4. Four year old car");
        System.out.println("5. More than four year old car");
        
        System.out.print("Enter your choice: ");
        int choice = in.nextInt();
        
        if (choice < 1 || choice > 5) {
            System.out.println("Wrong choice! Please select from 1, 2, 3, 4, 5.");
            return;
        }
        
        System.out.print("Enter showroom price: ");
        double price = in.nextDouble();
        double depValue = 0.0;
        
        switch(choice) {
            case 1:
                depValue = 0.1 * price;
                break;
            
            case 2:
                depValue = 0.2 * price;
                break;
            
            case 3:
                depValue = 0.3 * price;
                break;
            
            case 4:
                depValue = 0.5 * price;
                break;
            
            case 5:
                depValue = 0.6 * price;
                break;
            
            default:
                System.out.println("Wrong choice! Please select from 1, 2, 3, 4, 5.");
                break;
        }
        
        double amtPayable = price - depValue;
        
        System.out.println("Original Price = " + price);
        System.out.println("Depricated Value = " + depValue);
        System.out.println("Amount to be paid = " + amtPayable);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of In order to purchase an old car, the depreciated value can be calculated as per the tariff given below: Write a menu driven program to input showroom price and the number of years the car is used ('1' for one year old, '2' for two years old and so on). Calculate the depreciated value. Display the original price of the car, depreciated value and the amount to be paid.

Answered By

24 Likes


Related Questions