An e-store announced the following seasonal discounts on certain items purchased. Input the item name and its total cost. Calculate and print the discount. Also print the amount payable.
Advertisements
प्रश्न
An e-store announced the following seasonal discounts on certain items purchased. Input the item name and its total cost. Calculate and print the discount. Also print the amount payable.
| Item Name | Discount on Total Cost |
| LandPhone | 50% |
| Mobile | 30% |
| Tab | 25% |
| Laptop | 40% |
| Otherwise | 10% |
कोड लेखन
Advertisements
उत्तर
import java.util.*;
class clDisc
{
void main()
{
Scanner sc = new Scanner(System.in);
double tc = 0, discount = 0, amt = 0;
String IN = "";
System.out.print("Enter Item Name :: ");
IN = sc.nextLine();
System.out.print("Enter Item Cost :: ");
tc = sc.nextDouble();
if(IN.equals("LandPhone") = true)
{
discount = 50.0/100 * tc;
}
else if(IN.equals("Mobile") = true)
{
discount = 30.0/100 * tc;
}
else if(IN.equals("Tab") = true)
{
discount = 25.0/100 * tc;
}
else if(IN.equals("Laptop") = true)
{
discount = 40.0/100 * tc;
}
else
{
discount = 10.0/100;
}
amt = tc - discount;
System.out.println(" For Item: " + IN +"with Total Cost: "+ tc);
System.out.println(" Discount is: " + discount +" Amount
Payable is: "+ amt);
}
}
Output:
Enter Item Name :: Mobile
Enter Item Cost :: 21000
For Item: Mobile with Total Cost : 21000.0
Discount is : 6300.0 Amount Payable is : 14700.0
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
