如果语句和总数从未出现,则代码无法正常运行。我无法弄清楚什么是错的。我需要做些什么改变呢?方向如下。
成为健身中心会员的费用如下:(a)高级 公民折扣是30%; (b)如果会员资格购买并支付12或者 提前几个月,折扣为15%;或(c)如果超过5个人 购买培训课程,每次课程的折扣为20%。 编写菜单驱动程序,确定新成员资格的成本。 您的程序必须包含显示常规信息的方法 健身中心及其收费,一种获取所有必要信息的方法 确定会员费用,以及确定会员资格的方法 成本。使用适当的参数将信息传入和传出方法。
我应该使用哪种方法?
double grossdiscount1,grossdiscount2,grossdiscount3;
double grossprice1,grossprice2,grossprice3;
//end result of box calculation
double answerbox1,answerbox2,answerbox3;
double answerbox1b,answerbox2b,answerbox3b;
//Jtext inputs
double box1,box2,box3;
double discount1 = 0.30 ;
double discount2 = 0.20 ;
double discount3 = 0.15 ;
// prices PT=personal training MT=montly price
double pricePT =50.00;
double priceMT =100.00;
box1 = Double.parseDouble(jTextField1.getText());
box2 = Double.parseDouble(jTextField2.getText());
box3 = Double.parseDouble(jTextField3.getText());
// i brought these out of the if statement because the program won't run without
// them being stated
answerbox1b=box1*100;
grossdiscount1=(box1*priceMT)*discount3;// the amount saved
grossprice1=(box1*priceMT);
answerbox1=(grossprice1-grossdiscount1);
answerbox2b=(box2*pricePT);
grossdiscount2=(box2*pricePT)*discount2;// the amount saved
grossprice2=(box2*pricePT);
answerbox2=(grossprice2-grossdiscount2);
double total = answerbox1+answerbox2+answerbox1b+answerbox2b;
grossdiscount3=(total*discount3);// the amount saved
grossprice3=total;
answerbox3=(grossprice3-grossdiscount3);
if(box1<11 )
{
answerbox1b=box1*100;
}
else if(box1>12)
{
grossdiscount1=(box1*priceMT)*discount3;// the amount saved
grossprice1=(box1*priceMT);
answerbox1=(grossprice1-grossdiscount1);
}
if(box2<5 )
{
answerbox2b=(box2*pricePT);
}
else if(box2>=5)
{
grossdiscount2=(box2*pricePT)*discount2;// the amount saved
grossprice2=(box2*pricePT);
answerbox2=(grossprice2-grossdiscount2);
}
if(box3==1 )
{
grossdiscount3=(total*discount3);// the amount saved
grossprice3=total;
answerbox3=(grossprice3-grossdiscount3);
}
else if(box3==0);
{
}
jTextField4.setText(String.valueOf(total));
答案 0 :(得分:1)
else if语句未正确写入。除掉 ;为了正确的流程。
我还建议您检查与比较Java中的双打相关的任何线程