Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Simple method call problem

843789Apr 28 2009 — edited Apr 28 2009
This is probably simple but i dont know how to solve

I have class which contains this method, it taks an object p from another class called Person
    
public void addPerson(Person p)
{
        aPerson.add(p);
}
And another method which is a simple menu
public void mainMenu()
    {
         
    // Create Menu Text
    System.out.println(" Main Menu");
    System.out.println("---------------------------------------------");
    System.out.println("Please choose an option by entering the appropriate number:");
    System.out.println("1. Add Person");
    System.out.println("2. Exit");
    
    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
   
    try{    String menuC = stdIn.readLine();
            int menuChoice = Integer.parseInt(menuC);
    
                // Define Menu Options
                    switch(menuChoice)
                        {
                                case 1: 
                                        addPerson(Person p);    
                                    break;
            
                                case 2:  //** Exit
                                    break;

                        }
        }
    catch ( IOException ioe ) 
        {
        // won't happen too often from the keyboard
        }

        
    }
I want the method addPerson to be called if i type 1, however i get the error ')' expected on the line where i call the method in case 1.
If i take Person p as a parameter for mainMenu and then just call addPerson(p); it works perfectly, however i need it to want the parameter when the addPerson method is called not the mainMenu.

Any help on how to properly call the menu is appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 26 2009
Added on Apr 28 2009
10 comments
165 views