Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:51:23+00:00 2026-06-17T19:51:23+00:00

I am trying to write a java console menu but i can’t render it

  • 0

I am trying to write a java console menu but i can’t render it in the console. Here is the code i wrote so far.

package com.registrar;

import java.util.*;

class GUIMenu {
private Course[] courses = new Course[100];
private Person[] persons = new Person[1000];

public void display_menu() {
  System.out.println("****************MENU*****************");
  System.out.println("[1] Add Course\n[2] Add Student to Course \n[3] Verify Registration \n[4] Remove Student \n[5] Add Persons");
  System.out.println("**************************************");
  System.out.println("Selection: ");
}

public GUIMenu(){
Person p = null;
Scanner in = new Scanner (System.in);
int input = in.nextInt();

switch (input){
  case 1:
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter Course Name: ");
    String name = sc.nextLine();
    System.out.println("Enter Course ID:");
    Integer cID = sc.nextInt();
    System.out.println("Enter Instructor ID:");
    Integer pn = sc.nextInt();
    for(int i = 0; i < persons.length; i ++){
        System.out.println(persons[i]);
    }
    for(int i = 0; i<persons.length; i++){
        if(persons[i] !=null){
            if(persons[i].getId().intValue() == pn){
                System.out.println("Record Found");
                p  = persons[i];
            }
            else
                System.out.println("Record Not Found");
        }
    }
    Course c = new Course(name, cID);
    if(p!=null){
        Instructor ins = new Instructor(p);
        c.setInstructor(ins);
    }
    System.out.println(c + " has been created");

    for(int i = 0; i < courses.length; i ++){
        if(courses[i] == null){
            courses[i] = c;
            break;
        }
    }
    new GUIMenu();
  case 2:
      for(int i = 0; i < courses.length; i ++){
          if(courses[i] != null)
              System.out.println(courses[i]);
      }
      break;
  case 3:
    System.out.println ( "You picked option 3" );
    break;
  case 4:
    System.out.println ( "You picked option 4" );
    break;
  case 5:
      Scanner pers = new Scanner(System.in);
      System.out.println("Enter Person Name: ");
      String pname = pers.nextLine();
      System.out.println("Enter Person ID:");
      Integer oiID = pers.nextInt();
      Person per = new Person(pname, oiID);
      for(int i = 0; i < persons.length; i ++){
        if(persons[i] == null){
            persons[i] = per;
            break;
        }
      }
      display_menu();
  default:
    System.err.println("Unrecognized option");
}
}

public static void main ( String[] args ) {
    GUIMenu a = new GUIMenu();
    a.display_menu();
}
}

I am trying that after a selection on the menu the code returns the menu again after completing the code associated with that particular selection. What i am doing wrong? I dont see the menu at all displaying.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:51:24+00:00Added an answer on June 17, 2026 at 7:51 pm

    What i am doing wrong?

    Look at the code: This is where it starts:

    public static void main ( String[] args ) {
        GUIMenu a = new GUIMenu();  // This is executed first...
        a.display_menu();
    }
    

    let’s have a look at it

    public GUIMenu(){
        Person p = null;
        Scanner in = new Scanner (System.in);
        int input = in.nextInt(); // this is where it's waiting for your input.
        ...
    

    Looking at the flow of your code, it is pretty clear why the menu is not shown.

    EDIT:

    You are looking for something like this:

    public void runApplication() {
        // init Scanner
        boolean nextRound = true;
        while(nextRound) {
            displayMenu();
            int input = sc.nextInt();
            switch(input) {
                case 1: // do stuff
                    break;
                case 2: // this is the exit command
                    nextRound = false;
                    break;
                // more cases
                default:
                    // undefined input
            }
        }
    }
    

    So you use your constructor only for constructor relevant code and later call the runApplication() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write Java console application, the code is quite simple: public
I am trying this code in java: try { String url = http://url.com/file.ext; InputStream
I am trying to write a java ZIP util class as below: package fdbank.util;
I'm trying to write a java code to connect to an Oracle9i Enterprise Edition
I am trying to write Java code to let my XOOM communicate with our
I am trying to write some test code for my java application using Scalatest.
In trying to write more testable Java code, I have been using the Model-View-Presenter
I am trying at write a java program that hits a url over ssl,
I am trying to write a Java program that reads an input file consisting
I am trying to write a java application connecting to server connection channel with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.