944,172 Members | Top Members by Rank

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

Java Menu

Expand Post »
Hi All,

Hoping you can help with the following.

The psuedo code is:

1. Menu is displayed
2. User inputs a selection
3. That item is ran
4. on completion, the user is returned to 1 above.

the code i have so far is as follows, but its still exiting the program.
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. public static void main (String[]arguments)
  17. {
  18.  
  19.  
  20. System.out.println("Please make your selection");
  21. System.out.println("");
  22. System.out.println("(1) - New book : (2) - New user : (3) - New Load");
  23. Scanner scan = new Scanner(System.in);
  24. int menuSelect = scan.nextInt();
  25. switch (menuSelect)
  26. {
  27. case 1:
  28. menuSelect = 1;
  29. System.out.println("Selection 1");
  30. System.out.println("(1) - Main Menu");
  31. menuSelect=0;
  32. break;
  33.  
  34. case 2:
  35. menuSelect = 2;
  36. System.out.println("Selection 2");
  37. break;
  38.  
  39. case 3:
  40. System.out.println("Selection 3");
  41. break;
  42. }
  43. // menuSelect = 0;
  44.  
  45. while (menuSelect > 0 );
  46. }
  47.  
  48. }
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: Java Menu
just noticed a really stupid error. will post corrected code
Reputation Points: 15
Solved Threads: 15
Posting Pro in Training
whiteyoh is offline Offline
474 posts
since Jun 2009
Nov 2nd, 2009
0
Re: Java Menu
here it is corrected, but ive made it worse, but hope you can get an idea what im trying to achieve

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. public static void main (String[]arguments)
  17. {
  18.  
  19.  
  20. System.out.println("Please make your selection");
  21. System.out.println("");
  22. System.out.println("(1) - New book : (2) - New user : (3) - New Load");
  23. Scanner scan = new Scanner(System.in);
  24. int menuSelect = scan.nextInt();
  25. switch (menuSelect)
  26. {
  27. case 1:
  28. if(menuSelect ==1) {
  29. System.out.println("Selection 1");
  30. System.out.println("(1) - Main Menu");
  31. menuSelect=0;
  32. break;
  33. }
  34.  
  35. if (menuSelect ==2){
  36. case 2:
  37. menuSelect = 2;
  38. System.out.println("Selection 2");
  39. break;
  40. }
  41. case 3:
  42. System.out.println("Selection 3");
  43. break;
  44. }
  45. // menuSelect = 0;
  46.  
  47. while (menuSelect > 0 );
  48. }
  49.  
  50. }
Reputation Points: 15
Solved Threads: 15
Posting Pro in Training
whiteyoh is offline Offline
474 posts
since Jun 2009
Nov 2nd, 2009
0
Re: Java Menu
im going to close and re-open as i made a stupid mistake on the first post
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: Display Perfect Number
Next Thread in Java Forum Timeline: Need Initials





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


Follow us on Twitter


© 2011 DaniWeb® LLC