Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Main Menu (switch help)

Thread view: 
Tuurbo46 - 20 Nov 2005 11:19 GMT
Hi

Im currently experiencing some problems in getting the structure correct to
enable a user to select between menus.

I have chosen to create this menu in main and then allow all flow to other
classes from here. Is this considered the correct way of doing this?
Currently my version frows errors, saying there is to many brackets.  I have
looked at it for a long time and i cannot see a problem. I have added this
code below

Hope somebody can point me in the right direction.

Tuurbo

############################################

public static void main(String args[]) {

public void mainMenu(void)
int tempMyoption;
         do {
             tempMenuScreen();
             tempMyoption = readInOption();
             switch (tempMyoption) {
                        case '1':
                        System.out.println("one is working");
                        break;
                       case '2':
                       Systme.out.println("two is woriking");
                        break;
                        }
               }
     }

public void tempMenuScreen(void)
{

      System.out.println("");
      System.out.println("\t ### MAIN MENU ###");
      System.out.println("\t 1) Add new motorbike");
      System.out.println("\t 2) Exit");

      }
}
Andrew Thompson - 20 Nov 2005 12:11 GMT
> Im currently experiencing some problems in getting the structure correct to
> enable a user to select between menus.

It would seem those problems are overshadowed by compilation
problems, but UI design and compilation problems should be
covered in separate threads.

I will only adress the compilation errors and one or two
related matters.

> Currently my version frows errors,

Did you mean 'throws' errors?

If so, my reply is *rubbish*.  For a Java program to throw an
Error while running (the only time an 'Error' can be 'thrown')
is a very different to javac report compilation errors. ...

>..saying there is to many brackets.  

...Or, to put that another way, please always copy/paste
the error output.
<http://www.physci.org/codes/javafaq.jsp#exact>

>...I have
> looked at it for a long time and i cannot see a problem. I have added this
> code below

What you have added below is a snippet.
Posting an SSCCE of your problem is often much clearer.
<http://www.physci.org/codes/sscce.jsp>

It seems you have tried to define a method inside the
'main()' method (not allowed), but since it is a snippet,
it is hard to tell for sure what is happening.

> Hope somebody can point me in the right direction.

A better group for those new to Java is
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
Currently accepting short and long term contracts - on Earth.

Bjorn Abelli - 20 Nov 2005 12:12 GMT
> Im currently experiencing some problems in getting the structure correct
> to enable a user to select between menus.
>
> I have chosen to create this menu in main and
> then allow all flow to other classes from here.

> Is this considered the correct way of doing this?

Both yes and no.

the "main"-method contains the "main-flow" of an application, so when you're
dealing with procedural programming, it works.

As you're a beginner in Java, it could be a plausible start, until you're
ready to begin with the more intrinsic parts of object oriented programming,
where the "main-flow" in most cases is something else than just a sequential
flow.

> Currently my version frows errors, saying there is to
> many brackets.  I have looked at it for a long time and
> i cannot see a problem. I have added this code below

The error is more of *where* you have put the brackets...

- First, you *must* have a class to put the methods in.

- Second, you *can't* define a method for the same class within *another*
method.

- Third, "void" isn't legal as a parameter.

- Fourth, a "do"-loop must end with a "while"-condition.

- Fifth, for beginners a better newsgroup would be comp.lang.java.help.

With a better strategy of indentation, some of your errors would be easier
to spot.

Lets strip down your code to "only brackets"...

public static void main(String args[]) {

  public void mainMenu()

    do {
       switch (tempMyoption) {
       }
    }
  }

  public void tempMenuScreen() {
  }
}

Now it's obvious that you're missing a beginning bracket for the body of
"mainMenu".

You also see clearly that you've defined "mainMenu" and "tempMenuScreen"
*inside* the main-method, instead of defining them outside the main-method,
and just make calls to them from within the main-method.

Personally I find the "Allman style" more readable than the
"Kerrighan/Ritchie style", as I see the brackets lining up better that way.

// Bjorn A


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.