944,069 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 658
  • Java RSS
Nov 2nd, 2009
0

simple non gui menu

Expand Post »
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.

Java Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 15
Solved Threads: 15
Posting Pro in Training
whiteyoh is offline Offline
474 posts
since Jun 2009
Nov 2nd, 2009
0
Re: simple non gui menu
i have amended the code as follows, but i get an error when i want to return the value back to 0.

Java Syntax (Toggle Plain Text)
  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);
Reputation Points: 15
Solved Threads: 15
Posting Pro in Training
whiteyoh is offline Offline
474 posts
since Jun 2009
Nov 2nd, 2009
0
Re: simple non gui menu
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.
Reputation Points: 123
Solved Threads: 106
Posting Pro
quuba is offline Offline
573 posts
since Nov 2008
Nov 2nd, 2009
0
Re: simple non gui menu
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.
Reputation Points: 15
Solved Threads: 15
Posting Pro in Training
whiteyoh is offline Offline
474 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: hey i need some help looking over my coding
Next Thread in Java Forum Timeline: Hibernate Issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC