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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:41:30+00:00 2026-06-07T13:41:30+00:00

Basically i have a hashmap and the search method is missing a keyboard.next which

  • 0

Basically i have a hashmap and the search method is missing a keyboard.next which should allow the user to input the name they want to search for. There are no errors. The output does not allow an opportunity for the user to enter the name they want to search. The weird thing is i can use the userInput method and it works perfectly. Here is my code:
Store declaration

//Imports.
import java.util.Scanner;
//********************************************************************  
public class MainApp
{
    //The Scanner is declared here for use throughout the whole MainApp.
    private static Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args)
    {
        new MainApp().start();

    }
    public void start()
    {
//Create a Store named Store and add Employee's to the Store.
        EmployeeStore Store = new EmployeeStore();
        Store.add(new Employee ("James O' Carroll", 18,"hotmail.com"));

        Store.add(new Employee ("Andy Carroll", 1171,"yahoo.com"));

        Store.add(new Employee ("Luis Suarez", 7,"gmail.com"));
//********************************************************************      

/*Test Code.
        Store.searchByName("James O' Carroll");
        Store.print();
        Store.searchByEmail("gmail.com");
        Employee andy = Store.searchByEmail("hotmail.com");
        System.out.println(andy);
        Employee employee = Store.searchByName("James O' Carroll");
        if (employee != null)
        {
            employee.setEmployeeName("Joe");
            employee.setEmployeeId(1);
            employee.setEmployeeEmail("webmail.com");
           Store.edit(employee);
           Store.print();
        }*/
//********************************************************************      

        int choice ;
        System.out.println("Welcome to the Company Database.");
        do
        {
         choice = MenuMethods.getMenuChoice(
                "1.\tView All" +
                "\n2.\tAdd" +
                "\n3.\tDelete" +
                "\n4.\tDelete All " +
                "\n5.\tEdit" +
                "\n6.\tSearch" +
                "\n7.\tPrint"+
                "\n8.\tExit", 8, "Please enter your choice:", "Error [1,8] Only");
         //String temp = keyboard.nextLine();  This prevented entering the choice.
        switch (choice) 
        {
            case 1:
                 System.out.println("View All");
                Store.print();

                break;

        case 2:
             System.out.println("Add");
                Employee employee = MenuMethods.userInput();
                Store.add(employee);

                break;

        case 3:
             System.out.println("Delete");
                //Store.delete();


                break;

        case 4:
                System.out.println("Delete All");
                Store.clear();

                break;
        case 5:
           System.out.println("Edit");
           Employee employee2 = MenuMethods.userInput();
           Store.searchByName(employee2.getEmployeeName());
         if (employee2 != null)
        {
            employee2.setEmployeeName("Joe");
            employee2.setEmployeeId(1);
            employee2.setEmployeeEmail("webmail.com");
           Store.edit(employee2);
           Store.print();
        }

            break;
        case 6:
             System.out.println("Search");
             Employee employee1 = MenuMethods.userInputByName();
             Store.searchByName(employee1.getEmployeeName());


            break;
        case 7:
             System.out.println("Print");
            Store.print();

            break;
        case 8:
             System.out.println("Exit");

            break;
        }


        } while (choice != 8);

     }
}

//Imports
import java.util.Scanner;
//********************************************************************

public class MenuMethods 
{
    private static Scanner keyboard = new Scanner(System.in);



    //Methods for the Company Application menu.
    //Method for validating the choice.
         public static int getMenuChoice(String menuString, int limit, String prompt, String errorMessage) 
         {
                System.out.println(menuString);
                int choice = inputAndValidateInt(1, limit, prompt, errorMessage);
                return choice;
         }
    //********************************************************************
    //This method is used in the getMenuChoice method.
            public static int inputAndValidateInt(int min, int max, String prompt, String errorMessage) 
            {
                int number;
                boolean valid;
                do {
                    System.out.print(prompt);
                    number = keyboard.nextInt();
                    valid = number <= max && number >= min;
                    if (!valid) {
                        System.out.println(errorMessage);
                    }
                } while (!valid);
                return number;
            }
    //********************************************************************
    public static Employee userInput()
    {
         String temp = keyboard.nextLine();
         Employee e = null;
         System.out.println("Please enter the Employee Name:");
         String employeeName = keyboard.nextLine();
         System.out.println("Please enter the Employee ID:");
         int employeeId = keyboard.nextInt();
         temp = keyboard.nextLine();
         System.out.println("Please enter the Employee E-mail address:");
         String employeeEmail  = keyboard.nextLine();
         return e = new Employee(employeeName , employeeId, employeeEmail);

    }
    //********************************************************************
    public static Employee userInputByName()
    {

         Employee e = null;
         System.out.println("Please enter the Employee Name:");
         String employeeName = keyboard.nextLine();
         System.out.println("Please enter the Employee Name:");

         return e =  new Employee(employeeName);

    }
    //********************************************************************



}

Search Method in the mainApp

case 6:
             System.out.println("Search");
             Employee employee1 = MenuMethods.userInputByName();
             Store.searchByName(employee1.getEmployeeName());


            break;

The actual Search method.

public Employee searchByName(String employeeName) 
    {
        Employee employee = map.get(employeeName);    
        System.out.println(employee);
        return employee;
    }
//********************************************************************

The userInputByName method. This is where the problem seems to lie.

 public static Employee userInput()
    {
         String temp = keyboard.nextLine();
         Employee e = null;
         System.out.println("Please enter the Employee Name:");
         String employeeName = keyboard.nextLine();
         System.out.println("Please enter the Employee ID:");
         int employeeId = keyboard.nextInt();
         temp = keyboard.nextLine();
         System.out.println("Please enter the Employee E-mail address:");
         String employeeEmail  = keyboard.nextLine();
         return e = new Employee(employeeName , employeeId, employeeEmail);

    }
    //********************************************************************
    public static Employee userInputByName()
    {

         Employee e = null;
         System.out.println("Please enter the Employee Name:");
         String employeeName = keyboard.nextLine();
         System.out.println("Please enter the Employee Name:");

         return e =  new Employee(employeeName);

    }
    //********************************************************************
  • 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-07T13:41:32+00:00Added an answer on June 7, 2026 at 1:41 pm

    Let me try my best.

    First of all, why is there two println statements in your userInputByName()?

     public static Employee userInputByName()
        {
             Employee e = null; 
             System.out.println("Please enter the Employee Name:");
             String employeeName = keyboard.nextLine();
             System.out.println("Please enter the Employee Name:"); //!???
    
             return e =  new Employee(employeeName);
        }
    

    Then, in the case 6, you just call the method searchByName and does not check if the search is successful or not. I suggest:

    case 6:
        System.out.println("Search");
        Employee employee1 = MenuMethods.userInputByName();
        Employee foundEmployee = Store.searchByName(employee1.getEmployeeName());
    
        if (foundEmployee != null) {
            System.out.println("Found employee!");
        } else {
            System.out.println("Not Found!");
        }
    
        break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this HashMap: HashMap<String, Integer> m which basically stores any word (String) and
I basically have the classic many to many model. A user, an award, and
So basically, I have this content provider which I use to store and retrieve
So I have this method that should read a file and detect if the
I have the following as part of a method that is basically grabbing a
I basically have a program that filters records from one excel file to another
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a unix process running and it is doing some heavy processing
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have the following string in the format: A,B,C:D,E,F What I am trying

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.