10 Replies - 534 Views - Last Post: 18 January 2010 - 06:37 PM Rate Topic: -----

#1 al_buotan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 08-August 07

Help for menus

Posted 18 January 2010 - 12:24 AM

Posted Image

Can post your code? I just forgot how to do it using switch case statements..I need sample to navigate like the image above..dont wory i will only provide the code by call...
Any code will be appreciate...
Thanks...
Is This A Good Question/Topic? 0
  • +

Replies To: Help for menus

#2 al_buotan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 08-August 07

Re: Help for menus

Posted 18 January 2010 - 12:33 AM

hi everyone,
i am very new in java. i am having problem in SWITCH CASE STATEMENT. can anyone please help me to solve the following problem:

you have to write a program in java to generate the following menu with submenus:

about linked List

1: ADD ELEMENT
1-1: add first
1-2: add last
1-3: back to main menu

2: REMOVE ELEMENT
2-1: remove first
2-2: remove in between
2-3: remove last
2-4: back to main menu

3: OTHER FUNCTIONS
3-1: peek first
3-2: peek last
3-3: poll first
3-4: poll last
3-5: back to main

4: DISPLAY

5. EXIT

thank you,
regards,
al_buotan
Was This Post Helpful? 0
  • +
  • -

#3 0x00hex  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 11-January 10

Re: Help for menus

Posted 18 January 2010 - 01:11 AM

With 28 Posts I would presume you understand that without any attempt on your behalf (with code to show) it is unlikely you will get help. We don't do homework. I will be glad to help if you post some code you have written that demonstrates that you have at least tried to solve the problem assigned to you.
Was This Post Helpful? 0
  • +
  • -

#4 al_buotan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 08-August 07

Re: Help for menus

Posted 18 January 2010 - 01:23 AM

View Post0x00hex, on 18 Jan, 2010 - 12:11 AM, said:

With 28 Posts I would presume you understand that without any attempt on your behalf (with code to show) it is unlikely you will get help. We don't do homework. I will be glad to help if you post some code you have written that demonstrates that you have at least tried to solve the problem assigned to you.



import java.util.*;
import java.io.*;

public class MidProj
{
   public static void main(String[] args)
   {
		Scanner con = new Scanner(System.in);
		LinkedList<Integer> lst = new LinkedList<Integer>();
		int x;
		int x1;
		
		
		System.out.print("1. Add Element \n 2. Remove Element \n 3. Other Functions \n 4. Display \n 5. Exit \n Enter your choice: ");
		x = con.nextInt();
		
		switch (x) 
		{
			case 1: System.out.print("1. Add First \n 2. Add Last \n 3. Back to Main Menu \n Enter your choice: ");
					x1 = con.nextInt();
					switch (x1)
					{
						case 1: System.out.println("Add First: "); lst.addFirst;
								break;
						case 2: lst.addLast;
								break;
						case 3: 
					}
			case 2: menuB();
					break;
			case 3: menuC();
					break;
			case 4: System.out.println(lst);
					break;
			case 5: System.exit();
		}
   }
   
}



this is unfinish. Hope you can have any suggestios..

best regards,
al_buotan
Was This Post Helpful? 0
  • +
  • -

#5 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: Help for menus

Posted 18 January 2010 - 06:00 AM

Well i cannot actually read your image as its so dam small so please post a full size one and remember the following,

[rules][/rules]

have a try at the question and we will guide you :)

Just realised removing the .th. before .jpg will give the full size
Posted Image

so you want to decide between 5 options initially i am guessing

*add
*remove
*other
*display
*exit


So you have a switched based on five possible inputs.

int value = 2;

switch( value )
{
   case 0 : System.out.println("Selected Add");        break;
   case 1 : System.out.println("Selected Remove");  break;
   case 2 : System.out.println("Selected Other");      break;
   case 3 : System.out.println("Selected Display");    break;
   case 4 : System.out.println("Selected Exit");  System.exit(0);  // exit program ?
   default : System.out.println("Value Must Be between 0 and 4 Inclusive"); break;
}


So in the case above the value is 2, so we would expect to see Selected Other printed in the console.

Hope this helped ;)

This post has been edited by bbq: 18 January 2010 - 06:08 AM

Was This Post Helpful? 0
  • +
  • -

#6 al_buotan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 08-August 07

Re: Help for menus

Posted 18 January 2010 - 06:06 AM

thanks for that... of course it will help..

This post has been edited by al_buotan: 18 January 2010 - 06:25 AM

Was This Post Helpful? 0
  • +
  • -

#7 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: Help for menus

Posted 18 January 2010 - 06:08 AM

Check my original post, i have edited it :)
Was This Post Helpful? 0
  • +
  • -

#8 al_buotan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 08-August 07

Re: Help for menus

Posted 18 January 2010 - 06:28 AM

View Postbbq, on 18 Jan, 2010 - 05:08 AM, said:

Check my original post, i have edited it :)



yeah... for that one i have an idea how to do my problem...
thanks
Was This Post Helpful? 0
  • +
  • -

#9 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: Help for menus

Posted 18 January 2010 - 06:40 AM

how about just having some functions that you called based on what the user selects. For example if the user selects 2 then you must move into another selection process where they must make a choice based on other options

*remove first
*remove in betwen
*remove last
*back to main

So to do that you would just replace case 1 : System.out.println("Selected Remove"); break; with for example a call to a method / function case 1 : selectionTwoMade() ; break;

Where selectionTwoMade() looks something like this

private void selectionTwoMade()
{
   int choice;
   System.out.println("Make a Choice :: 1,2,3,4");
   choice = input.nextInt();

  switch(choice)
  {
       // before the break statement you would need to call
       // a function to remove
       case 1 : break;  // remove first
       case 2 : break;  // remove middle
       case 3 : break;  // remove last
       case 4 : return; // return to Main Menu
       default : System.out.println("Bad Selection"); return; // also return to main
 
  }

}


Thats enough code for you to get started in some way. Post back once you have attempted it :)

This post has been edited by bbq: 18 January 2010 - 06:41 AM

Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Help for menus

Posted 18 January 2010 - 06:16 PM

You have a break missing
	   switch (x) 
		{
			case 1: System.out.print("1. Add First \n 2. Add Last \n 3. Back to Main Menu \n Enter your choice: ");
					x1 = con.nextInt();
					switch (x1)
					{
						case 1: System.out.println("Add First: "); lst.addFirst;
								break;
						case 2: lst.addLast;
								break;
						case 3: 
					}
					break;			<----------------------------
			case 2: menuB();


Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Help for menus

Posted 18 January 2010 - 06:37 PM

Duplicated topics merged
Please avoid double posts :angry:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1