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 8879809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:02:02+00:00 2026-06-14T20:02:02+00:00

I have created my menu with do~while(true); but every time the user insert a

  • 0

I have created my menu with do~while(true); but every time the user insert a number, instead of running the program it shows the the menu again! what do you think?

// my main method

public static void main(String[] args) {

    DataReader reader = new DataReader(); // The reader is used to read data from a file

    // Load data from the file
    if(reader.loadData(args[0])) {          // The filename is entered using a command-line argument

        vehicles= reader.getVehicleData(); // Store the arrays of Vehicle

        // Display how many shapes were read from the file
        System.out.println("Successfully loaded " + vehicles[0].getCount() + 
                           " vehicles from the selected data file!");
        displayMenu();
    }
}

// dispaly menu method

private static void displayMenu() {
    Scanner input = new Scanner(System.in);

    do {
        System.out.println("\n\n          Car Sales Menu");
        System.out.println("--------------------------------------");
        System.out.println("1 - Sort vehicles by owner's Last Name");
        System.out.println("2 - Sort vehicles by vehicle Model");
        System.out.println("3 - Sort vehicles by vehicle Cost\n");
        System.out.println("4 - List All Vehicles");
        System.out.println("5 - List All Cars");
        System.out.println("6 - List American Cars Only (Formal)");
        System.out.println("7 - List Foreign Cars only (Formal)");
        System.out.println("8 - List All Trucks");
        System.out.println("9 - List All Bicycles");
        System.out.print("\nSelect a Menu Option: ");
        getInput(input.next()); // Get user input from the keyboard 
    }
    while(true); // Display the menu until the user closes the program
}

// getInput method

private static void getInput(String input) {
    switch(Convert.toInteger(input)) {
        case 1: // Sort Vehicles by Owner's Last Name
            Array.sortByOwnerName(vehicles);
            break;
        case 2: // Sort Vehicles by Vehicle Make & Model
            Array.sortByVehicleMakeModel(vehicles);
            break;
        case 3: // Sort Vehicles by Vehicle Cost
            Array.sortByVehicleCost(vehicles);
            break;
        case 4: // List All Vehicles
            displayVehicleData(0);
            break;

        default:
            System.out.print("The entered value is unrecognized!");
            break;
    }
}
  • 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-14T20:02:03+00:00Added an answer on June 14, 2026 at 8:02 pm

    Because you have while(true);, this means that the menu it will be in a infinite loop until a break is call.

    Try to do something like:

     do {
            System.out.println("\n\n          Car Sales Menu");
            System.out.println("--------------------------------------");
            System.out.println("1 - Sort vehicles by owner's Last Name");
            System.out.println("2 - Sort vehicles by vehicle Model");
            System.out.println("3 - Sort vehicles by vehicle Cost\n");
            System.out.println("4 - List All Vehicles");
            System.out.println("5 - List All Cars");
            System.out.println("6 - List American Cars Only (Formal)");
            System.out.println("7 - List Foreign Cars only (Formal)");
            System.out.println("8 - List All Trucks");
            System.out.println("9 - List All Bicycles");
            System.out.print("\nSelect a Menu Option: ");
        try {
            int input = Integer.parseInt(getInput(input.next())); // Get user input from the keyboard 
    
    
            switch (input) {
            case 1:  // do something
                     break;
            case 2:  // do something
                     break;
            ...
           }
          } catch (NumberFormatException e) { ... }
    
        }
        while(true); // Display the menu until the user closes the program
    

    You can use switch to process the input, and depending on input do the respective action.

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

Sidebar

Related Questions

I have created a dropdown menu with jquery: here Everything is ok but in
I have created a drop down menu using JQuery but when I test it
I have created menu with tabs and under tabs I use <button> s. Normally
I have created one menu using div animating in the middle i have structured.
I have created a horizontal menu with 5 tab options using a ul and
i have created an options menu for my database class. Upon launching the options
Hey Guys, i have created the following Menu Structure: <div id=menu> <ul> <li><a href=#>Main
I have created an Activity that will behave like a popup menu is actually
I have created a jquery plugin to expand/collapse ul,li something like a accordion menu
I want that the menu i have created for testing entries should come in

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.