Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

menu validation problem for some reason i am stuck in a infinite loop

$
0
0
the problem is i am stuck in the loop forever even when the menuChouse is less than 4 and i have no clue on whats went wrong.

// declare main menu variables
  		Scanner in;
  		boolean gotInput;
  		int menuChouse;
  		String inputString = "";
  		
  		// loop valid unitll menuChouse is <= 4
  		do
  		{
  			// display the menu
  			System.out.println();
  			System.out.println("*************************************************");
  			System.out.println("*** Main menu");
  			System.out.println("*** ");
  			System.out.println("*** 1. Proccess New Job (using decimal values)");
  			System.out.println("*** 2. Proccess new job (using RGB hexadecimal values)");
  			System.out.println("*** 3. Calibrate Dispenser");
  			System.out.println("*** 4. Dipsplay Summary of Jobs");
  			System.out.println("*** 0. Exit");
  			System.out.print("***\n*** Please choose a option: ");
  			
  			
  			// loop valid until gotInput true
  			do
  			{
  				// set gotInput to true as i assume i am going to get the input
  				gotInput = true;
  				System.out.println(gotInput); //###################
  				try
  				{
  					// set new scanner
  					in = new Scanner(System.in);
  					
  					inputString = in.next();
  				}
  				catch (Exception e)
  				{
  					System.out.println("A unknow error has occured please contact the admin");
  					gotInput = false;
  				}
  				System.out.println(gotInput); //###################
  			} while (!gotInput);
  			
  			// check if input is a digit
  			try
  			{
  				menuChouse = Integer.parseInt(inputString);
  				// is an integer
  				System.out.println(menuChouse);//###################
  			} 
  			catch (NumberFormatException e) 
  			{
  				// not an integer
  				menuChouse = 200000;
  			}
  			System.out.println(menuChouse);//###################
  			
  		} while (menuChouse > 4);
  		
  		return menuChouse;
  	}



any help is appreciated

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>