Sigma Car Company has announced the following festive discounts on the purchase of
certain Diesel and Petrol cars:
Write a program in Java to input the cost of car and the type of car purchased (D for
Diesel Car and P for Petrol Car) from a customer. Using the above criteria compute
and print the net amount to be paid by a customer.
discount = (discount rate /100) × amount of purchase
Net amount = amount of purchase – discoun
Answers
Answer:
Write a program in Java to input the cost of car and the type of car purchased (D for
Diesel Car and P for Petrol Car) from a customer. Using the above criteria compute
and print the net amount to be paid by a customer.
discount = (discount rate /100) × amount of purchase
Net amount = amount of purchase – discoun
Answer:import java.util.Scanner;
class Car_Company
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
String car_type;
double net_amount;
double dis=0.0;
double cost;
System.out.println("Enter Car Type = ");
car_type=ob.nextLine();
System.out.println("Enter Car Cost = ");
cost=ob.nextDouble();
if(cost <= 600000)
{
if(car_type.equals("D"))
dis=0.0;
if(car_type.equals("P"))
dis=(5.0/100)*cost;
}
if(cost > 600000 && cost <= 1000000)
{
if(car_type.equals("D"))
dis=(5.0/100)*cost;
if(car_type.equals("P"))
dis=(7.6/100)*cost;
}
if(cost > 1000000 && cost <= 1500000)
{
if(car_type.equals("D"))
dis=(7.5/100)*cost;
if(car_type.equals("P"))
dis=(10.0/100)*cost;
}
if(cost > 1500000)
{
if(car_type.equals("D"))
dis=(10.0/100)*cost;
if(car_type.equals("P"))
dis=(15.0/100)*cost;
}
net_amount=cost-dis;
System.out.println("Net Amount = "+net_amount);
}
}
Explanation: