
December 2nd, 2012, 05:28 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Time spent in forums: 48 m 40 sec
Reputation Power: 0
|
|
|
Not sure which type of loop to use
Hey,
As part of a project im doing, I want the user to input a choice from a menu(1,2,or3) if they pick one of these choices they get asked whether they want pick another item, if they pick yes they then pick another choice, if they pick no they leave this part of the screen. But I can't get the programm to keep running after they enter their choice for the 2nd time. I tried using a do while loop, but I got confused where to place "Do you want to order again". Here is my code for it.
The code tags made my code look worse?
Thanks
Quote: | public void yourChoice(){ String choicePizzaAsString; String continueAsString=""; int pizzaChoice; choicePizzaAsString=JOptionPane.showInputDialog("Please enter your choice:"); pizzaChoice=Integer.parseInt(choicePizzaAsString); if(pizzaChoice !=1 && pizzaChoice !=2 && pizzaChoice !=3) { choicePizzaAsString = JOptionPane.showInputDialog("Invalid choice-please re-enter"); } else { continueAsString=JOptionPane.showInputDialog("Would you like to order anything else y/n"); } if(continueAsString.equals("y")){ choicePizzaAsString = JOptionPane.showInputDialog("Invalid choice-please re-enter"); } else if(continueAsString.equals("n")){ JOptionPane.showMessageDialog(null,"Please select a pizza"); }} |
|