I'm a total newbie to Java.
I'm creating a very simple banking system as a college project. I'm doing ok... logging in the user, the displaying a Main Menu with options to select from. However Im using a If statement for the selection and once I have selected an option (for example = check account balance) I cant go back to the Main Menu (unless I write the whole thing out again, which would be daft).
I have tried to write a method (?) to display the menu, I can then put this at the end of my if statement to return the user to the Main Menu. However I can get it to work... Below is my menu code and below that the code i attempted for the method, if I can resolve this then im pretty much flying at the minute its the only thing holding me back!!!
Expand|Select|Wrap|Line Numbers
- //Show menu and get users choice
- accChoice = JOptionPane.showInputDialog(null, "Account Menu \n" +
- "What would you like to do? \n" +
- " 1 - Check Balance.\n" +
- " 2 - Make A Withdrawl.\n" +
- " 3 - Make A Deposit.\n"+
- " 4 - Amend Overdraft.\n" +
- " 5 - Exit.\n" +
- "Please enter your choice:");
- //direct users choice
- if (accChoice.equals(accChoice1))
- {
- System.out.println("1 - Check Balance.");
- }
- else if (accChoice.equals(accChoice2))
- {
- System.out.println("2 - Make A Withdrawl");
- }
- else if (accChoice.equals(accChoice3))
- {
- System.out.println("3 - Make A Deposit.");
- }
- else if (accChoice.equals(accChoice4))
- {
- System.out.println("4 - Amend Overdraft.");
- }
- else if (accChoice.equals(accChoice5))
- {
- System.out.println("5 - Exit");
- }
Expand|Select|Wrap|Line Numbers
- private String displayMainMenu()
- {
- String accChoice;
- accChoice = JOptionPane.showInputDialog(null, "Account Menu \n" +
- "What would you like to do? \n" +
- " 1 - Check Balance.\n" +
- " 2 - Make A Withdrawl.\n" +
- " 3 - Make A Deposit.\n"+
- " 4 - Amend Overdraft.\n" +
- " 5 - Exit.\n" +
- "Please enter your choice:");
- return accChoice;
- }