English

In order to purchase an old car, the depreciated value can be calculated as per the tariff given below: No. of years used 1 2 3 4 Above 4 years Rate of depreciation 10% 20% 30% 40% 50% - Computer Applications

Advertisements
Advertisements

Question

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

No. of years used Rate of depreciation
1 10%
2 20%
3 30%
4 40%
Above 4 years 50%

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. 

Answer in Brief

Solution

import java.util.*;
public class Q14{
public static void main(String g[]){
int n; // number of years used
double price, drate, dval, amt; // price, depreciationrate, depreciated value
Scanner obj = new Scanner(System.in);
System.out.printIn("Enter the showroom price of the car");
price = obj.nextDouble();
System.out.printIn("Enter the number of years, the car had been used");
n = obj.nextInt();
switch(n)
{ case 0: 
  case 1: drate = 10.0 / 100; break;
  case 2: drate = 20.0 / 100; break;
  case 3: drate = 30.0 / 100; break;
  case 4: drate = 50.0 / 100; break;
default: drate = 60.0 / 100;
}
dval = price * drate;
amt = price − dval; ’
System.out.printIn("\n\nOriginal Price: Rs. " + price);
System.out.printin("Depreciated Value: Rs. " + dval);
System.out.printIn("Amount Paid for the car: Rs. " + amt);
}}
shaalaa.com
  Is there an error in this question or solution?
Chapter 1.08: Conditional Statements in Java - EXERCISES [Page 102]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 1.08 Conditional Statements in Java
EXERCISES | Q VI. 14. | Page 102
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×