I have some problems here. I want the program to give me my total bill when I press N but it keeps asking the same question over and over again. When I press Y, it gives basically does the same thing again.
Also, how can I show the amount of change the person should get back? Example: If the 2 items cost $5 and the person pays $10, I would like it to say Your change is $5.
Thank you.
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: ");
}
}