473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Display Menu

Hi All

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
  1. //Show menu and get users choice
  2.         accChoice = JOptionPane.showInputDialog(null, "Account Menu \n" +
  3.                                           "What would you like to do? \n" +
  4.                                           " 1 - Check Balance.\n" +
  5.                                           " 2 - Make A Withdrawl.\n" +
  6.                                           " 3 - Make A Deposit.\n"+
  7.                                           " 4 - Amend Overdraft.\n" +
  8.                                           " 5 - Exit.\n" +
  9.                                           "Please enter your choice:");
  10.  
  11.     //direct users choice
  12.         if (accChoice.equals(accChoice1))
  13.         {
  14.             System.out.println("1 - Check Balance.");
  15.         }
  16.         else if (accChoice.equals(accChoice2))
  17.         {
  18.             System.out.println("2 - Make A Withdrawl");
  19.         }
  20.         else if (accChoice.equals(accChoice3))
  21.         {
  22.             System.out.println("3 - Make A Deposit.");
  23.         }
  24.         else if (accChoice.equals(accChoice4))
  25.         {
  26.             System.out.println("4 - Amend Overdraft.");
  27.         }
  28.         else if (accChoice.equals(accChoice5))
  29.         {
  30.             System.out.println("5 - Exit");
  31.         }
below is my method(s) code:

Expand|Select|Wrap|Line Numbers
  1. private String displayMainMenu()
  2.     {
  3.         String accChoice;
  4.         accChoice = JOptionPane.showInputDialog(null, "Account Menu \n" +
  5.                                           "What would you like to do? \n" +
  6.                                           " 1 - Check Balance.\n" +
  7.                                           " 2 - Make A Withdrawl.\n" +
  8.                                           " 3 - Make A Deposit.\n"+
  9.                                           " 4 - Amend Overdraft.\n" +
  10.                                           " 5 - Exit.\n" +
  11.                                           "Please enter your choice:");
  12.         return accChoice;
  13.  
  14.    }
May 22 '09 #1
2 9393
JosAH
11,448 Expert 8TB
If you can wait one more day or so then I'll post a little article about this topic because I've seen people struggle with this item more than often. The solution (which you can reuse over and over again!) will be a bit of code that represents a single menu item as well as an entire menu. You can nest menus at will and put in "back" and "quit" menu items whereever you want.

kind regards,

Jos

edit: done; read the 'insights' section of the Java forum: it contains a little article about this very topic.
May 30 '09 #2
Hi Josah,

Can I check where I can find the article on the display menu in java? Thanks!!
Jul 28 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Al Sav | last post by:
Hi, I am trying to create a menu for asp.net page. The menu-detail list display, when mouse hovers over the main menu list, like you see in regular windows apps. When the detail-menu-list window...
6
by: Jamie | last post by:
Hi all, I have a page in which I display a menu which is a table within a div element. Each cell in the table is a menu item with an "onclick" event handler assigned. I want to make it so...
7
by: Marc | last post by:
Hi everyone. I am having trouble with a stylesheet in mozilla. It is part of turning a list into a menu: #menu li{ margin: 0; display: inline; vertical-align: bottom;
12
by: mdb | last post by:
My app has a notify icon in the systray. I want the left mouse click to initiate a menu, and a right-mouse click to do something else. Normally, for a button, I would listen to MouseDown and if I...
4
by: txican | last post by:
the HTML is: ---------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html> <head> <title>foo</title>...
3
by: hzgt9b | last post by:
Using VS2005, VB.NET, I am developing a windows app that has a DataGridView. I want to enable the display of a context menu on this DataGridView only when a specific set of keys is also pressed...
0
by: rehanmomin | last post by:
Just to start off, I am writing a web application using C#. I have a Menu which is binded to an XML datasource. There are three menu items each with submenus and a textbox where I want to display...
2
by: giandeo | last post by:
Hello all, It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help....... I am working with an asp page...
2
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.