. A cloth showroom has announced the following festival discounts on the purchase of items based on
the total cost of the items purchased:
Total cost Discount (in Percentage)
Less than Rs. 2000 5%
Rs. 2001 to Rs. 5000 25%
Rs. 5001 to Rs. 10000 35%
Above Rs. 10000 50%
Write a program to input the total cost and to compute and display the amount to be paid by the customer after availing the discount. Three methods also their input(), calculate() and display().
Solution
import java.io.*;
/**
* class Showroom
*
*/
public class Showroom
{
private double cost; // For cost
private double dis; // For Discount
private double amt; // For Amount
void input()throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
System.out.println("Enter Cost of the product:");
cost=Double.parseDouble(br.readLine());
}
void calculate()
{
if(cost<=2000)
dis = cost * 0.05;
else if(cost>2000 && cost<=5000)
dis = cost * 0.25;
else if(cost>5000 && cost<=10000)
dis = cost *0.35;
else
dis = cost * 0.5;
amt= cost - dis;
}
void display()
{
System.out.println("Cost of the product="+cost);
System.out.println("Discount given="+dis);
System.out.println("Amount Paid="+amt);
}
public static void main(String args[])throws IOException
{
Showroom ob=new Showroom();
ob.input();
ob.calculate();
ob.display();
}
}
Output:
Enter Cost of the product:
5630
Cost of the product=5630.0
Discount given=1970.4999999999998
Amount Paid=3659.5
No comments:
Post a Comment