-
Set-up Main Menu
Hi everyone
I have created separate four class:
and I want to setup a main menu, so if a user press 1, then it goes to the Annulus Class, if a user press 2, it goes to Diameters Class and if a user press 3, it goes to the Circumference class.
I've spent all day trying to figure it out how I can set up a menu. I've attach my work what I've done so far. Can you help me please?
Many thanks!
Code:
public class MainMenu
{
public static CheckLinesIn CLI = new CheckLinesIn();
public static Annulus A = new Annulus();
public static Diameters D = new Diameters();
public static Circumferences C = new Circumferences();
public static void menu (String[] args)
{
-
well you're on the right track but just a note your public static void menu (String[] args) is suppose to be main not menu. here's the basic code of how u can do this. have fun coding
Code:
import java.io.*;
public class MainMenu
{
public static CheckLinesIn CLI = new CheckLinesIn();
public static Annulus A = new Annulus();
public static Diameters D = new Diameters();
public static Circumferences C = new Circumferences();
public static void main (String[] args) throws IOException //throws IOException doesn't report any erros
{ //main not menu!
String input = new String();
System.out.println("Please enter a choice");
System.out.println("1. CheckLinesIn");
System.out.println("2. Annulus");
System.out.println("3. Diameters");
System.out.println("4. Circumferences");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
input = br.readLine();
if(input.equals("1"))
{
CLI.menu();
}
else if (input.equals("2"))
{
A.menu();
}
else if (input.equals("3"))
{
D.menu();
}
else if (input.equals("4"))
{
C.menu();
}
}
}
class CheckLinesIn
{
public static void menu ()
{
System.out.println("In class CheckLinesIn");
}
}
class Annulus
{
public static void menu ()
{
System.out.println("In class Annulus");
}
}
class Diameters
{
public static void menu ()
{
System.out.println("In class Diameters");
}
}
class Circumferences
{
public static void menu ()
{
System.out.println("In class Circumferences");
}
}
¿Red Baron?
[code] /* dont forget code tags! */ [/code]
Come visit the Café!
-
Red Baron,
Many thanks for the coding, I now realised how the main menu works!
Now, I have one more feature that requires to add is that after a user selected a menu, and perform the calculation, I want the program to ask the user if they wish to perform another calculation.
Eg: 'Do you want to perform another calculation? (y/n)' and if the user press y or Y then it starts to the main menu asking the user to select which calculation. If the user press n or N then program stops.
I can't figure out how I can do this?
Can you please help?
-
Code:
import java.io.*;
public class MainMenu
{
public static CheckLinesIn CLI = new CheckLinesIn();
public static Annulus A = new Annulus();
public static Diameters D = new Diameters();
public static Circumferences C = new Circumferences();
public static void main (String[] args) throws IOException //throws IOException doesn't report any erros
{ //main not menu!
String input = new String();
for(;;)
{
System.out.println("Please enter a choice");
System.out.println("1. CheckLinesIn");
System.out.println("2. Annulus");
System.out.println("3. Diameters");
System.out.println("4. Circumferences");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
input = br.readLine();
if(input.equals("1"))
{
CLI.menu();
}
else if (input.equals("2"))
{
A.menu();
}
else if (input.equals("3"))
{
D.menu();
}
else if (input.equals("4"))
{
C.menu();
}
System.out.println("Do you want to perform another calculation? y/n");
input = br.readLine();
if (input.equals("n") || input.equals("N"))
{
break;
}
//no need for continue cause of infinite loop
}
}
}
class CheckLinesIn
{
public static void menu ()
{
System.out.println("In class CheckLinesIn");
}
}
class Annulus
{
public static void menu ()
{
System.out.println("In class Annulus");
}
}
class Diameters
{
public static void menu ()
{
System.out.println("In class Diameters");
}
}
class Circumferences
{
public static void menu ()
{
System.out.println("In class Circumferences");
}
}
¿Red Baron?
[code] /* dont forget code tags! */ [/code]
Come visit the Café!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks