非常感谢你,但现在它没有添加正确的价格,保持它在第一个添加量,例如它应该是6.99 +.20 + .20 + .20,具体取决于我添加的数量
public void addToppings()
{
String[] topChoice = {"Pepperoni", "Mushrooms", "Pineapple", "Bacon", "Beef Bites(IDK)"};
int add;
String topPick = " ";
String total = " ";
double price = 0;
int index = 0;
do
{
topPick = (String)JOptionPane.showInputDialog(null,"What toppings do you want?","Add Your Toppings", JOptionPane.QUESTION_MESSAGE, null, topChoice, topChoice[0]);
if ((topPick != null) && (topPick.length() > 0))
{
price += 0.20;
index++;
}
add = JOptionPane.showConfirmDialog(null,"Would you like to add more toppings?","More Toppings",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
}
while (add == JOptionPane.YES_OPTION);
return;
}
答案 0 :(得分:0)
移动此行
topPick = (String)JOptionPane.showInputDialog(null, "What toppings do you want?","Add Your Toppings", JOptionPane.QUESTION_MESSAGE, null, topChoice, topChoice[0]);
进入do while
循环。