simple non gui menu

Thread Solved

Join Date: Jun 2009
Posts: 140
Reputation: whiteyoh is an unknown quantity at this point 
Solved Threads: 2
whiteyoh whiteyoh is offline Offline
Junior Poster

simple non gui menu

 
0
  #1
26 Days Ago
Hi All,

Im attempting to make a simple java menu system. the psueo code is as follows

1. user is presented with menu
2. selection is made
3. that action is ran, i.e make a new user (i have this code seperate, which works)
4. the user is returned to the main menu.

what is actually happening is it keeps ending. I tried using a do while, but i cant seem to get my head around it.

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package week7;
  7. //import java.io.*;
  8. //import java.io.IOException;
  9. import java.util.Scanner;
  10. /**
  11.  *
  12.  * @author Administrator
  13.  */
  14. public class whileDoTest {
  15.  
  16. @SuppressWarnings("empty-statement")
  17. public static void main (String[]arguments)
  18. {
  19.  
  20. int menuSelect = 0;
  21. if (menuSelect ==0){
  22. System.out.println("Please make your selection");
  23. System.out.println("");
  24. System.out.println("(1) - New book : (2) - New user : (3) - New Load");
  25. Scanner scan = new Scanner(System.in);
  26. menuSelect = scan.nextInt();
  27. }else{
  28. switch (menuSelect)
  29. {
  30. case 1:
  31. if(menuSelect == 1) {
  32. System.out.println("Selection 1");
  33. System.out.println("(1) - Main Menu");
  34.  
  35. break;
  36. }menuSelect = 0;
  37. case 2:
  38. if(menuSelect ==2) {
  39. System.out.println("Selection 2");
  40. break;
  41. }
  42. case 3:
  43. if (menuSelect ==3){
  44. System.out.println("Selection 3");
  45. break;
  46. }
  47.  
  48.  
  49. }
  50.  
  51. }
  52. }
  53. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 140
Reputation: whiteyoh is an unknown quantity at this point 
Solved Threads: 2
whiteyoh whiteyoh is offline Offline
Junior Poster
 
0
  #2
26 Days Ago
i have amended the code as follows, but i get an error when i want to return the value back to 0.

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package week7;
  7. //import java.io.*;
  8. //import java.io.IOException;
  9. import java.util.Scanner;
  10. /**
  11.  *
  12.  * @author Administrator
  13.  */
  14. public class whileDoTest {
  15.  
  16. @SuppressWarnings("empty-statement")
  17. public static void main (String[]arguments)
  18. {
  19.  
  20.  
  21.  
  22. System.out.println("Please make your selection");
  23. System.out.println("");
  24. System.out.println("(1) - New book : (2) - New user : (3) - New Load");
  25. Scanner scan = new Scanner(System.in);
  26. int menuSelect = scan.nextInt();
  27.  
  28. // switch (menuSelect)
  29.  
  30. do{
  31.  
  32.  
  33. System.out.println("Selection 1");
  34. System.out.println("(1) - Main Menu");
  35. menuSelect ==0;
  36. }while (menuSelect==1);
  37.  
  38. do{
  39. if(menuSelect ==2) {
  40. System.out.println("Selection 2");
  41. }while (menuSelect==2);
  42. do{
  43. System.out.println("Selection 3");
  44. }
  45. while (menuSelect ==3);
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz
 
0
  #3
26 Days Ago
whiteyoh, look at static int ConsoleOptionGUI(String s) method http://www.daniweb.com/forums/thread231390.html
Yet you will not always write all the code in the main method.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 140
Reputation: whiteyoh is an unknown quantity at this point 
Solved Threads: 2
whiteyoh whiteyoh is offline Offline
Junior Poster
 
0
  #4
26 Days Ago
Hi,

Handy link!

I have managed to get it working by using an "if" inside the do.

Ive also split down the code to sub classes.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC