我刚刚开始学习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;
}