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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:47:35+00:00 2026-06-07T16:47:35+00:00

Hey im having trouble with my edit method in the EmployeeStore. Basically im trying

  • 0

Hey im having trouble with my edit method in the EmployeeStore. Basically im trying to ask the user to search through the map for an employee by name and then i want to print out the employee they search for and then i want to let the user edit the 3 variables of the employee class. Can anyone help. Here is my code:

Edit choice in the mainApp
  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;

MenuMethods

//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 employee = null;
         System.out.println("Please enter the Employee Name:");
         String employeeName = keyboard.nextLine();
         return employee = new Employee(employeeName , null, null);

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



}

EmployeeStore

//Imports.
import java.util.HashMap;
import java.util.Scanner;
//********************************************************************
public class EmployeeStore
{
    HashMap<String, Employee> map;
    private static Scanner keyboard = new Scanner(System.in);

//Constructor.  
    public EmployeeStore()
    {
        map = new HashMap<String,Employee>();
    }
//********************************************************************
//Hashmap Methods.
//Add to the Hashmap : Employee.
    public void add(Employee employee)
    {

        map.put(employee.getEmployeeName(), employee);
    }
//********************************************************************
//Remove from the Hashmap : Employee.
    public void remove(String key)
    {
      //Remove the Employee by name.
        map.remove(key);
    }
//********************************************************************
//Clear the Hashmap : Employee.
    public void clear()
    {
        map.clear();
    }
    //********************************************************************
//Print the Hashmap : Employee. 
    public void print()
    {
        System.out.println("\n********Employee's in the Company.********");
        for (Employee employee : map.values())
        {
            //System.out.println(employee); to print the toString of Employee class
            //or:
            System.out.println("Employee Name:\t" + employee.getEmployeeName());
            System.out.println("Employee Id:\t" + employee.getEmployeeId());
            System.out.println("E-mail:\t"+ employee.getEmployeeEmail());
        }

    }
    public Employee get(String name){
        return map.get(name);
    }
    /*public void searchByName ()
    {
        //(for(Employee e : map.values()) {...}) 
        //and check for each employee if his/her email matches the searched value
        for(Employee e : map.values())
        {
            System.out.println(e);
            map.equals(getClass());

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

    public Employee searchByEmail(String email) 
    {
        for (Employee employee : map.values())
        {
            if (email.equals(employee.getEmployeeEmail()))
            {
                System.out.println(employee);
                return employee;
            }
        }
        return null;
    }
//********************************************************************
    public void edit(Employee employee)
    {
        map.put(employee.getEmployeeName(), employee);
    }


//********************************************************************


//********************************************************************  
//********************************************************************


}
  • 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-07T16:47:37+00:00Added an answer on June 7, 2026 at 4:47 pm

    A (persistance) store shouldn’t have an edit method at all. It should provide methods to

    • C – create a new item
    • R – read an item
    • U – update an existing item
    • D – delete an existing item

    Editing is done by an editor, that will make use of the stores create method (for new items) or read and update methods (for editing existing items)


    for the userInputByName – get the name from the keyboard and use the store to return the employee, if any:

    System.out.println("Please enter the Employee Name:");
    String employeeName = keyboard.nextLine();
    return getStore().searchByName();
    

    You only have find a way to implement the magic getStore() method so that you get the instance of the employee store that can provide the employees.

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

Sidebar

Related Questions

Hey guys, I'm having trouble trying to find the user's longitude and location as
Hey guys I'm having trouble looping through some XML. Im trying to capture the
Hey I'm having trouble trying to figure this one out. UITableView has a method
Hey all! Having a little trouble with my stack. Im trying to print each
Hey guys I am having trouble trying to convert my web app to support
Hey im new to database design and having trouble trying to figure this one
Hey, I currently am having trouble trying to get this to work. Here's a
Hey all, I'm trying to write a sort function but am having trouble figuring
Hey basically just having a little trouble with the following, submitting a message from
Hey, i'm trying to get a project to work, but i am having trouble

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.