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.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package week7;
//import java.io.*;
//import java.io.IOException;
import java.util.Scanner;
/**
 *
 * @author Administrator
 */
public class whileDoTest {

    @SuppressWarnings("empty-statement")
    public static void main (String[]arguments)
    {

        int menuSelect = 0;
       if (menuSelect ==0){
            System.out.println("Please make your selection");
            System.out.println("");
            System.out.println("(1) - New book     :     (2) - New user     :     (3) - New Load");
            Scanner scan = new Scanner(System.in);
            menuSelect = scan.nextInt();
       }else{
            switch (menuSelect)
            {
                case 1:
                   if(menuSelect == 1) {
                    System.out.println("Selection 1");
                    System.out.println("(1) - Main Menu");
                    
                    break;
                   }menuSelect = 0;
                case 2:
                    if(menuSelect ==2) {
                    System.out.println("Selection 2");
                    break;
                    }
                case 3:
                    if (menuSelect ==3){
                    System.out.println("Selection 3");
                    break;
                    }
                   

            }
            
            }
    }
}

i have amended the code as follows, but i get an error when i want to return the value back to 0.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package week7;
//import java.io.*;
//import java.io.IOException;
import java.util.Scanner;
/**
 *
 * @author Administrator
 */
public class whileDoTest {

    @SuppressWarnings("empty-statement")
    public static void main (String[]arguments)
    {

        
       
            System.out.println("Please make your selection");
            System.out.println("");
            System.out.println("(1) - New book     :     (2) - New user     :     (3) - New Load");
            Scanner scan = new Scanner(System.in);
            int menuSelect = scan.nextInt();
      
           // switch (menuSelect)

            do{
               
                  
                    System.out.println("Selection 1");
                    System.out.println("(1) - Main Menu");
                    menuSelect ==0;
                   }while (menuSelect==1);
            
           do{
                    if(menuSelect ==2) {
                    System.out.println("Selection 2");
                    }while (menuSelect==2);
           do{
                    System.out.println("Selection 3");
                    }
                    while (menuSelect ==3);

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.

This question has already been answered. Start a new discussion instead.