Java の学習を始めたばかりで、switch ステートメントを使用する必要がありますが、ケースごとに計算のすべての値を追跡し、それを合計する必要があります。どうすればできますか?
ここに私のコードがあります
switch(productNo)
{
case 1:
lineAmount1 = quantity * product1;
orderAmount = +lineAmount1;
textArea.append(productNo +"\t"
+ quantity + "\t"
+ "$" + lineAmount1 +"\t"
+ "$" + orderAmount + "\n" );
break;
case 2:
lineAmount2 = quantity * product2;
orderAmount = + lineAmount2;
textArea.append(productNo +"\t"
+ quantity + "\t"
+ "$" + lineAmount2 +"\t"
+ "$" + orderAmount + "\n" );
break;
case 3:
lineAmount3 = quantity * product3;
orderAmount = +lineAmount3;
textArea.append(productNo +"\t"
+ quantity + "\t"
+ "$" + lineAmount3 +"\t"
+ "$" + orderAmount + "\n" );
break;
case 4:
lineAmount4 = quantity * product4;
orderAmount = +lineAmount4;
textArea.append(productNo +"\t"
+ quantity + "\t"
+ "$" + lineAmount4 +"\t"
+ "$" + orderAmount + "\n" );
break;
case 5:
lineAmount5 = quantity * product5;
orderAmount = +lineAmount5;
textArea.append(productNo +"\t"
+ quantity + "\t"
+ "$" + lineAmount5 +"\t"
+ "$" + orderAmount);
break;
}