English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
0

First of all, to explain the idea behind my question ill explain that i want to create a text-based program. I would like to create a main menu. I talked to my teacher about this, and he said i should use the switch statement. Now, i would like to know how to use this statement to open another class.

Like for exmaple, main menu gives you the following options(inventory system)(keyboard input):

1) View Engines

2) View Life jackets

3) Add a new item

....

What must be written in the case 1, case 2, to bring me to these other classes..

2007-03-23 23:29:45 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

To use switch you need an input, so you can ask that from the user using:

System.out.print("Input menu number (1,2,3): ");

And then, process the input using switch to choose the case, like this:
switch (number) {
case 0:
System.out.println("Menu 1");
break;
case 1:
System.out.println("Menu 2");
break;
case 2:
case 3:
case 4:
System.out.println("Continue all the way, chum");
break;

Just like that... simple, rite? :)

2007-03-23 23:57:49 · answer #1 · answered by Ruzgar 2 · 0 0

its such a hard thing, maybe option.

2007-03-23 23:40:01 · answer #2 · answered by Archangel 3 · 0 0

fedest.com, questions and answers