I'm supposed to make a menu with choices, the choices being different kinds of java syntax.

import java.util.*;

public class Start 
{
    public void menu()
    {
    System.out.println("[1] If\n[2] If else\n[3] For loop\n[4] Switch Statement\n[5] One dimension");
    System.out.print("Select program: ");
    }
    public void backend()
    {
     System.out.println("[9] Menu\n[0] Quit");

     Scanner q = new Scanner(System.in);

     switch (q.nextInt())
       {
       case 0:
       System.out.println("End of the program.");
       break;

       case 9:
       new Input();
       break;

       default:
       System.err.println("Please choose the appropriate options.");
       break;

       }
     }
     public void ifex()
     {

        System.out.println("[6] Gender");
        Scanner pb = new Scanner(System.in);
        switch(pb.nextInt())
       {

           case 6:
           gender();
           break;
       }
     }
     public void ifelse()
     {
         System.out.println("[10] Legal Age");
         Scanner gg = new Scanner(System.in);
         switch(gg.nextInt())
        {
          case 10:   
          break;
        } 
      }

    public void gender()
      {
       System.out.println("Choose your gender\n[7] Male\n[8] Female");
       Scanner gb = new Scanner(System.in);
       switch(gb.nextInt())
        {
         case 7:
         System.out.println("Your gender is Male");
         new backend();
         break;

         case 8:
         System.out.println("Your gender is Female");
         new backend();
         break;

         default:
         System.err.println("That is not on the options. Please try again.");
         break;
        }
       }   

         public void age()
        {
        System.out.println("Enter your age");
        Scanner gb = new Scanner(System.in);
        Int age = input.nextInt();

          if (age < 12);
          System.out.println("You are not yet in a legal age.");

          System.out.println("You are in a legal age");
          backend();
          break;

       }

  }          

  public Start()
  {
  Scanner in = new Scanner(System.in);
  menu();

    switch (in.nextInt())
    {
    case 1: 
    ifex();
    break;

    case 2:
    ifelse();
    break;
    }

}

  public static void main (String[]args)
  {
     new Start();
  }
}

Recommended Answers

All 4 Replies

Its a very bad idea to have multiple Scanners usig the same input stream (System.in). You never know which Scanner will read the next character from the stream, or which Scanners may have read ahead and thus consumed characters that you hoped to read with a different Scanner.
Create just one Scanner at the start of the program and use that for everything.

Your bracketing/indentaton style is confusing (although perfectly legal).

ankitdixit:

In your opinion, why is an online web-basedIDE better than an IDE on your own computer?

commented: So you don't have to worry if your code is kept private or safe any longer? +16
commented: it isn't. They're slower, usually very clunky, and of course you've no idea whether your code is secure from being stolen by whomever runs the website +16
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.