Okay take a look at this program that I was instructed to write from the book I have for Java:
Okay here is the problem:Code:import javax.swing.*; //import all the swing methods public class ModifiedInvoiceApp //declare the InvoiceApp class { public static void main(String[] args) //main routine of InvoiceApp class { String choice = ""; //empty string while (!(choice.equalsIgnoreCase("n"))) //begin while loop (while value of choice is not 'n' ignoring case) { String inputString = JOptionPane.showInputDialog("Enter order total: "); //get the order from the user double orderTotal = Double.parseDouble(inputString); //reparse the input number so that it can be used double discountAmount = 0; //empty double if (orderTotal >= 500) discountAmount = orderTotal * .20; else if (orderTotal >= 250 && orderTotal < 500) discountAmount = orderTotal * .15; else if (orderTotal >= 100 && orderTotal < 250) discountAmount = orderTotal * .10; else if (orderTotal < 100) discountAmount = 0; double invoiceTotal = orderTotal - discountAmount; //set value of invoiceTotal String message = "Order total: " + orderTotal + "\n" + "Discount amount: " + discountAmount + "\n" + "Invoice total: " + invoiceTotal + "\n\n" + "Continue (Y/N)? "; //message string for final dialog choice = JOptionPane.showInputDialog(null, message, "Invoice Application", JOptionPane.INFORMATION_MESSAGE); //final dialog } System.exit(0); //close the thread from the JOptionPane methods } }
The line that looks like this:
It's checking for the wrong letter to continue. It should be "y". Well I changed it, compiled the program, and for some reason, it creates an infinite loop. However, when I change it back to "n", it doesn't create and infinite loop and runs the program like it should. It seems to be just a simple change of a letter and it creates an infinite loop. What is going on here? I can't figure it out. Thanks again.Code:while (!(choice.equalsIgnoreCase("n")))




Reply With Quote