I have made a command prompt text based menu interface. It is a 'league
menu' that displays 10 options and you type '2' or whatever and it then does
something (e.g. display a list of teams). It works fine, except I want to
have a sub-menu ('Club Menu') that also has a list of 10 options. I can get
it to display this club menu, but when you type any number at that point it
just returns to the league menu again.
I think the problem is with this piece of code:
public static void main (String[] args)
{
MainProgram testdata = new MainProgram();
testdata.createLEAGUEPremiership();
System.out.println("");
System.out.println("**TEST DATA HAS BEEN GENERATED**");
System.out.println("");
int selector =0;
do
{
selector = testdata.leagueMenu();
testdata.leagueProcessSelector(selector);
}
while (selector != 666);
}
Do I need another one of these do/while - 'selector' bits of code lower down
in the leagueMenu method?
This is the code for the leagueMenu, though I dont know if you need it. The
other methods are very long but I can add them on request.
public int leagueMenu() // throws IOException
{
System.out.println("");
System.out.println("LEAGUE MENU (" + L1.getLeagueName() + ")");
System.out.println("=====================");
System.out.println("1. View league table");
System.out.println("2. Change League name");
System.out.println("3. Add a new club");
System.out.println("4. Delete a club");
System.out.println("5. Generate fixture list");
System.out.println("6. Record a result");
System.out.println("7. View current top scorer(s)");
System.out.println("9. CLUB MENU (Update/View an existing club)");
System.out.println("666. -- Exit Program --"); //this doesnt work
System.out.println("Select option: ");
try {
BufferedReader keyboardInput = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("");
return Integer.parseInt(keyboardInput.readLine());
} catch (Exception e) {
System.err.println(e.getMessage());
}
return 0;
}
Hal Rosser - 05 Nov 2004 02:52 GMT
for 'nested' command-line menus, use nested while loops