这是一个程序,我做的一切工作,除了它不显示折扣价格,从而最终成本太。我正在使用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");
}
}
}
1条答案
按热度按时间khbbv19g1#
您需要将整数除法转换为双精度。例如: