ユーザーがアイテムの原価と数量を入力したときに、レジシステムがアイテムの合計を計算するようにしたいという私の割り当てについて、このアイデアがあります。
それは機能しているように見えましたが、私の主な問題を引き起こしました.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」という言葉の下にのみあります。
私は髪を引き裂いているので、どんな助けも素晴らしいでしょう!!!!
ありがとう、
ヴィニー。