Results 1 to 7 of 7
  1. #1
    Auclown is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default Need help with building two menus.

    Hi. While I am doing homework I got in stuck with 'building two menu' problem.

    What I have to do is build two menus.

    I do not use any GUI thing with this, just use bunch of letters.

    At first, I have to make the first menu shows up when I run it. And then, if I put number 3 at the first menu, then the second menu shows up.

    When I am on the second menu and put number 4, come back to the first menu.

    So the output of the code should be like this:

    - First Menu
    1. Hello
    2. Hi
    3. What?
    4. Bye

    Your choice?: 3 <- using Keyboard.readInput() method here, and put 3 in.

    - Second Menu
    1. Bon jour
    2. Ni hao
    3. Namaste
    4. Nothing

    Your choice?: 4

    - Fisrt Menu
    1. Hello
    2. Hi
    3. What?
    4. Bye

    Your choice?: 4

    Goodbye. :D


    like this.

    Both menu has 4 options to choose.

    So here's my code for the first, the second menu and selecting options.



    public class WhatToDo {

    public void start() {

    //this part is temporarily empty..

    }

    private void firstMenu(){

    System.out.println("1. Saying hello to your parents.");

    System.out.println("2. Saying hello to your friends.");

    System.out.println("3. I do not want to say hello to anybody but playing computer games.");

    System.out.println("4. Goodbye");

    }

    private void secondMenu(){

    System.out.println("1. Go play XBOX360.");

    System.out.println("2. Go play PS3.");

    System.out.println("3. Go play PC.");

    System.out.println("4. Maybe I can say hello to someone..");

    }

    private int selectOptions(){

    String optionNum = Keyboard.readInput();

    int number = Integer.parseInt(optionNum);

    if( .....


    I really don't know how to make this work.

    In the selectOption() method, I do not even know how to make it work different for those two menus' options.

    I mean, if I code like


    if(number==1){

    System.out.println("Hello");

    }else if(number==2){

    ..... this, then I think it would print only "Hello" if I put 1 in the Keyboard thing, no matter of what menu I am looking.

    I have tried to code this part like this: if(firstMenu().number==1){...} but there were only bunch of errors.

    Can anybody help me with the code?

  2. #2
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    256
    Rep Power
    3

    Default Re: Need help with building two menus.

    you need a greeting like, "hello which menu would you like 1 , 2 or 3. then take this input using a Scanner and if statements and if the user pressed 1, call the first menu option. Is this what you are stuck on?

  3. #3
    b4viral is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: Need help with building two menus.

    i suggest use switch case and put a callback to first menu method(in fourth option of second menu), just make sure you use exit 0 after to avoid repeated loops

  4. #4
    Join Date
    Apr 2013
    Posts
    41
    Rep Power
    0

    Default Re: Need help with building two menus.

    You code very weird my friend... follow something on the lines of this
    Java Code:
    import java.util.Scanner;
    
    public class lol {
    	static int toDo;
    	static boolean stop = false, Menu = false;
    
    	public static void main(String[] args) {
    		Scanner scan = new Scanner (System.in);
    		FirstMenu();
    		do{
    		System.out.print("What would you like to do? ");
    		toDo = scan.nextInt();
    		Display(toDo);
    		}
    		while(stop != true);
    	}
    	public static void Display(int i){
    		i = toDo;
    		//1
    		if(i == 1){
    		System.out.println("Hello");
    		}
    		//2
    		if(i == 2){
    			SecondMenu();
    			Menu = true;
    		}
    		//3
    		//4
    		if(i == 4 && Menu == false){
    			stop = true;
    		}
    		
    	}
    	public static void FirstMenu(){
    		System.out.println("1. Saying hello to your parents.");
    
    		System.out.println("2. Saying hello to your friends.");
    
    		System.out.println("3. I do not want to say hello to anybody but playing computer games.");
    
    		System.out.println("4. Goodbye");
    	}
    	public static void SecondMenu(){
    		System.out.println("1. Go play XBOX360.");
    
    		System.out.println("2. Go play PS3.");
    
    		System.out.println("3. Go play PC.");
    
    		System.out.println("4. Maybe I can say hello to someone..");
    	}
    
    }
    just finish up that code and youre golden

  5. #5
    Auclown is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default Re: Need help with building two menus.

    Quote Originally Posted by monkeyjr97 View Post
    you need a greeting like, "hello which menu would you like 1 , 2 or 3. then take this input using a Scanner and if statements and if the user pressed 1, call the first menu option. Is this what you are stuck on?
    Yes.. I really don't know how to do that.

    And I have not learned about Scanner thing so maybe I should not use Scanner method in this homework.

    Thank you

  6. #6
    Auclown is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default Re: Need help with building two menus.

    I am really not good at coding java, so can you please tell me how to do that callback stuff?

    Thank you

  7. #7
    Auclown is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

Similar Threads

  1. MenuBar, menus & actions
    By Agrata in forum AWT / Swing
    Replies: 3
    Last Post: 01-05-2012, 03:01 PM
  2. JQuery Menus
    By anithajerome in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-01-2010, 11:28 AM
  3. Canvas Menus
    By gedas in forum Java 2D
    Replies: 5
    Last Post: 02-18-2010, 11:13 PM
  4. customizing menus
    By rotte001 in forum Eclipse
    Replies: 0
    Last Post: 02-06-2010, 08:04 PM
  5. Menus Not Displaying
    By kahaj in forum AWT / Swing
    Replies: 12
    Last Post: 09-23-2009, 05:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •