我在这里遇到了一些问题。我希望程序在我按N时给我总账单,但它一遍又一遍地问同样的问题。当我按Y时,它基本上会再次做同样的事情。
另外,如何显示该人应该获得的更改量?示例:如果2件物品的价格为5美元且该人支付10美元,我希望它说您的更改是5美元。
谢谢。
String temp = null;
temp = JOptionPane.showInputDialog("Enter The amount of Items :");
int Size = Integer.parseInt(temp);
String[] ItemName = new String[Size];
Integer[] ItemId = new Integer[Size];
Double[] ItemPrice = new Double[Size];
Integer index = 0;
while (index < Size) {
ItemName[index] = JOptionPane.showInputDialog("Enter The Item Name:");
temp = JOptionPane.showInputDialog("Enter Item ID for " + ItemName[index] + " :");
ItemId[index] = Integer.parseInt(temp);
temp = JOptionPane.showInputDialog("Enter The Price " + ItemName[index] + " :");
ItemPrice[index] = Double.parseDouble(temp);
index++;
}
for (int i = 0; i < Size; i++) {
System.out.printf("%s\t %d\t %.2f\t\n", ItemName[i], ItemId[i], ItemPrice[i]);
}
surName = JOptionPane.showInputDialog("Please enter your surname");
number = JOptionPane.showInputDialog("Please enter the Amount Paid: ");
amountPaid = Double.parseDouble(number);
System.out.println("Your surname is " + surName);
System.out.print("Enter the Item ID for the item");
compare = keyboard.nextInt();
while (Complete == false) {
while (a < Size) {
if (compare == ItemId[a]) {
Price = Price + ItemPrice[a];
}
a++;
}
System.out.print("Sale Complete? Enter Y or N");
response = keyboard.next();
if (response == "Y") {
System.out.println("The toal bill is" + Price);
} else {
System.out.print("Please answer the following: ");
}
}