这是我制作的一个程序,除不显示折扣价和最终成本外,其他所有功能均正常。我正在使用if else梯形图和扫描仪(这行是不必要的,但是如果我写的文字不够多,堆栈溢出将不会让我发问)如果您能帮助我,我将非常感谢。这是代码:
/**A Shopkeeper has decided to give out discount and an assured gifts to his customer on the basis of total cost of the item purchased:
TOTAL COST DISCOUNT GIFT
<= 2000 5% WALL CLOCK
2001 – 5000 10% BAG
5001 – 10000 15% ELECTRIC IRON
>10000 20% WRIST WATCH
Write a program to input the total cost. Compute discount. Display the total cost, discount obtained,
final amount to be paid and the gift received by the customer.*/
import java.util.*;
class P1
{
public static void main(String a[])
{
Scanner in = new Scanner(System.in);
System.out.println("Input the total cost of the product...");
double cost = in.nextDouble();
if(cost<=0)
{
System.out.println("Invalid Price");
}
else if(cost<=2000)
{
System.out.println("Total cost of the product "+cost);
System.out.println("Discount is 5%");
double dis = 5/100*cost;
double finalcost = dis+cost;
System.out.println("Discounted price is "+dis);
System.out.println("Final amount to be paid is "+finalcost);
System.out.println("Gift recieved is a Wall Clock");
}
else if(cost>=2001 && cost<=5000)
{
System.out.println("Total cost of the product "+cost);
System.out.println("Discount is 10%");
double dis = 10/100*cost;
double finalcost = dis+cost;
System.out.println("Discounted price is "+dis);
System.out.println("Final amount to be paid is "+finalcost);
System.out.println("Gift recieved is a Bag");
}
else if(cost>=5001 && cost<=10000)
{
System.out.println("Total cost of the product "+cost);
System.out.println("Discount is 15%");
double dis = 15/100*cost;
double finalcost = dis+cost;
System.out.println("Discounted price is "+dis);
System.out.println("Final amount to be paid is "+finalcost);
System.out.println("Gift recieved is an Electric Iron");
}
else if(cost>10000)
{
System.out.println("Total cost of the product "+cost);
System.out.println("Discount is 20%");
double dis = 20/100*cost;
double finalcost = dis+cost;
System.out.println("Discounted price is "+dis);
System.out.println("Final amount to be paid is "+finalcost);
System.out.println("Gift recieved is a Wrist Watch");
}
else
{
System.out.println("Invalid Price");
}
}
}
您需要将整数除法转换为两倍。例如:
double dis = (double) 5 / 100 * cost;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句