我对我的任务有这个想法,我希望收银系统在用户输入它的成本价格和所述项目的数量时计算项目的总数。
这似乎可行,但随后导致了我的主要问题 - 我想让用户在说 10 次交易之后输入字母“T”,以找出当天的总收入。
我尝试在计算等中使用带有 BigDecimal 数学类的 for 循环。我的计算中的“valueOf”一词有错误,Eclipse 一直试图将我的值更改为“long”,我很确定这是不对的.
我的解释并不令人惊讶,所以我会给你我写的代码,并在我的错误旁边放置注释..
try{
Scanner in = new Scanner (System.in);
String t = "T";
int count;
for (count = 1;count<=10;count++){
System.out.println("\n\nValue of Item " + count + " :");
BigDecimal itemPrice = in.nextBigDecimal();
System.out.println("Quantity of item " + count + " :");
BigDecimal itemQuantity = in.nextBigDecimal();
BigDecimal itemTotal = (BigDecimal.valueOf(itemPrice).multiply // error here
(BigDecimal.valueOf(itemQuantity))); // error here
System.out.println("\nTotal for item(s): £" + itemTotal);
count++;
while (t == "T"){
BigDecimal amountOfItems = (BigDecimal.valueOf(itemTotal).divide // error here
(BigDecimal.valueOf(itemQuantity))); // error here
BigDecimal totalTakings = (BigDecimal.valueOf(itemTotal).multiply // error here
(BigDecimal.valueOf(amountOfItems))); // error here
System.out.println("The Total Takings For Today is £" + totalTakings + " " );
}
}
}
}
}
就像我说的那样,eclipse 用来显示错误的“红线”仅在我的 BigDecimal 计算中的“valueOf”字样下方。
任何帮助都会很棒,因为我要把头发扯掉!!!!
谢谢,
维尼。