Advertisements
Advertisements
प्रश्न
A computer store announced stock clearing sale. They were offering both a discount and a gift. Input the purchase amount and print the amount payable. Also print the gift that should be given to the customer
| Purchase Amount (pa) (in Rupees) |
Discount on pa | Gift |
| рa >= 20000 | 25% | music system |
| рa <20000 & ра >= 15000 |
20% | wrist watch |
| pa < 15000 & ра >= 12000 |
16% | wall clock |
| pa < 12000 & pa >= 5000 |
11% | digital table clock |
| Otherwise | 5% | pen set |
कोड लेखन
Advertisements
उत्तर
importjava.util.*; //imports all the classes of the utility package
class clGift
{
void main()
{
Scanner sc = new Scanner(System.in);
int pa=0;
double discount = 0, amt = 0; String gift = "";
System.out.print("Enter Purchase Amount :: ");
pa = sc.nextInt();
if(pa >= 20000)
{
discount = 25.0/100;
gift = "Music System";
}
else if(pa >=15000)
{
discount = 20.0/100;
gift = "Wrist Watch";
}
else if(pa >= 12000)
{
discount = 16.0/100;
gift = "Wall Clock";
}
else if(pa >=5000)
{
discount = 11.0/100;
gift = "Digital Table Clock";
}
else
{
discount = 5.0/100;
gift = "Pen Set";
}
amt = pa - (pa * discount);
System.out.println("For Purchase Amount: " + pа);
System.out.println("Discount is: "+ (pa * discount) +" Amt Payable is: "+ amt);
System.out.println(".. and the gift offered is : " + gift);
}
}
Output:
Enter Purchase Amount :: 25000
For Purchase Amount : 25000
Discount is : 6250.0 Amount Payable is : 18750.0
and the gift offered is : Music System
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
