考虑代码:
public double calculatePrice()
{
int discount = 0 ;
double totalPrice=itemCount*itemPrice;
double netPrice;
for(int i=0;i<NOOFITEMS.length;i++)
{
/* if(i==0)
{
if(itemCount<NOOFITEMS[i])
{ discount=0;
break;
}
}
/*if(i==NOOFITEMS.length-1)
{
if(itemCount>NOOFITEMS[i])
{ discount=50;
break;
}
}
if(itemCount<NOOFITEMS[i]&&itemCount>NOOFITEMS[i+1])
{
discount=DISCOUNTPERCENTAGE[i];
}*/
discount=10;
}
System.out.println("discount "
+discount);
System.out.println("totalprice "
+totalPrice);
netPrice=totalPrice-(totalPrice*(discount/100));
return netPrice;
}
输出::
Bill ID: 501
Item NAME: grocery
NO of Item: 11
Price of Item: 250.0
discount 10
totalprice 2750.0
net price 2750.0
TRAINEE ID: 502
TRAINEE NAME: fruits
Price of Item: 300.0
Item NO: 15
discount 10
totalprice 4500.0
net price 4500.0
的值"netprice"
应该4050 [4500-(4500*(10/100)]
按照给定的语句。但该值4500
始终输出..discount/100
计算不正确。总是忽略小数部分。无法弄清楚错误..!