它是一个小卖部计划!
public void sale() {
if (!ingredients.isEmpty()) {
printFood();
String choice = JOptionPane.showInputDialog("Enter Your choices seperatad by a # to indicate quantity");
String[] choices = choice.split(" ");
String[] ammounts = choice.split("#");
for (int i = 0; i < choices.length; i++) {
int foodPos = (Integer.parseInt(choices[i])) - 1;
int ammount = Integer.parseInt(ammounts[i+1]);
try {
foods.get(foodPos).sale(ammount);
} catch (IndexOutOfBoundsException e) {
System.out.println("Ingredient does not exsist");
}
}
}
}
http://paste.ubuntu.com/5967772/
给出错误
线程“主”java.lang.NumberFormatException 中的异常:对于输入字符串:java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) 处的“1#3”在 java.lang.Integer.parseInt(Integer.java:492 ) 在 java.lang.Integer.parseInt(Integer.java:527)