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

  • SEARCH
  • Home
  • 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 8301521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:58:52+00:00 2026-06-08T16:58:52+00:00

Hey my edit method is not running correctly. I’ll tell you step by step

  • 0

Hey my edit method is not running correctly. I’ll tell you step by step how it isn’t supposed to work.
Step 1: The user inputs a name such as Luis Suarez and then the searchByName method will search for this name in the Employee Store.
Step 2:The User will again input employee details and this time it will overwrite the employee they wish to edit.

I will now show you my code:

MainApp

//---------------------------------------------------------------------------------------
//              Name:        Case 4: Edit.
//              Description: Choice 4 gives the user an option to edit the employee's in the store.
//                           This consists of changing the employee's name,id and e-mail address.
//---------------------------------------------------------------------------------------
            case 5:
                System.out.println("Edit");
                Employee employeeEdit = MenuMethods.userInputByName();
                Store.searchByName(employeeEdit.getEmployeeName());
                if (employeeEdit != null) 
                {
                    employeeEdit.setEmployeeName("Joe");
                    employeeEdit.setEmployeeId(1);
                    employeeEdit.setEmployeeEmail("webmail.com");
                    Store.edit(employeeEdit);
                }
                break;

UserInputByName

//---------------------------------------------------------------------------------------
//  Name:        userInputByName.
//  Description: This method is used in the MainApp to give the user capability to search by name.
//---------------------------------------------------------------------------------------
    public static Employee userInputByName() 
    {
        // String temp is for some reason needed. If it is not included
        // The code will not execute properly.
        String temp = keyboard.nextLine();
        Employee e = null;
        System.out.println("Please enter the Employee Name:");
        String employeeName = keyboard.nextLine();

        return e = new Employee(employeeName);

    }

Edit

// ---------------------------------------------------------------------------------------
    // Name: Edit.
    // ---------------------------------------------------------------------------------------
    public void edit(Employee employee) 
    {
        map.put(employee.getEmployeeName(), employee);
    }

Employee

//---------------------------------------------------------------------------------------
//  Employee class.
//---------------------------------------------------------------------------------------
public class Employee
{
//---------------------------------------------------------------------------------------
//  Variables to be used in the employee store.
//---------------------------------------------------------------------------------------
    private String employeeName;
    private int employeeId;
    private String employeeEmail;
//---------------------------------------------------------------------------------------
//  Name:        Constructors.
//  Description:
//---------------------------------------------------------------------------------------
    public Employee(String employeeName, int employeeId, String employeeEmail) 
    {
        this.employeeName = employeeName;
        this.employeeId = employeeId;
        this.employeeEmail = employeeEmail;
    }
//---------------------------------------------------------------------------------------
//  Overloading the constructor for the use with userInputByName method.
//---------------------------------------------------------------------------------------
    public Employee(String employeeName) 
    {
        this.employeeName = employeeName;
    }
//---------------------------------------------------------------------------------------
//  Name:   Getters.
//---------------------------------------------------------------------------------------
    public String getEmployeeEmail() 
    {
        return employeeEmail;
    }

    public String getEmployeeName() 
    {
        return employeeName;
    }
    public int getEmployeeId() 
    {
        return employeeId;
    }
//---------------------------------------------------------------------------------------
//  Name:   Setters.
//---------------------------------------------------------------------------------------
    public void setEmployeeEmail(String employeeEmail) 
    {
        this.employeeEmail = employeeEmail;
    }
    public void setEmployeeName(String employeeName) 
    {
        this.employeeName = employeeName;
    }
    public void setEmployeeId(int employeeId)
    {
        this.employeeId = employeeId;
    }

//---------------------------------------------------------------------------------------
//  Name:   toString.
//---------------------------------------------------------------------------------------
    public String toString() 
    {
        return "\t\t\tEmployee\n" +
                "********************************************************************\n"+
                "Employee Name: "+ employeeName +"\n"+ 
                "Employee Id: " + employeeId +"\n"+  
                "Employee Email: " + employeeEmail;
    }
//---------------------------------------------------------------------------------------
}

SearchByName

// ---------------------------------------------------------------------------------------
    // Name: Search by Name.
    // ---------------------------------------------------------------------------------------
    public Employee searchByName(String employeeName)
    {
        Employee employee = map.get(employeeName);
        System.out.println(employee);
        return 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-08T16:58:53+00:00Added an answer on June 8, 2026 at 4:58 pm

    have a look at this small demo :

    HashMap<String, Employee> map = new HashMap<>();
    map.put("Pendo826", new Employee("Pendo826", 1, "Pendo826@gmail.com"));
    
    Employee e = map.get("Pendo826"); // get emp instance by name
    e.setEmployeeName("Pendo"); // emp name of that instance edited 
    System.out.println(map.get("Pendo826").getEmployeeName()); // name is changed within map
    

    so simply your case 5 :

    System.out.println("Edit");
    Employee employeeEdit = MenuMethods.userInputByName();
    Employee e = Store.searchByName(employeeEdit.getEmployeeName());
    if (e != null) 
    {
      e.setEmployeeName("Joe");
      e.setEmployeeId(1);
      e.setEmployeeEmail("webmail.com");
      // Store.edit(employeeEdit); // no need as you already have made changes to reference e
    }
    break;
    

    after that if you view all you will have the changes

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

Sidebar

Related Questions

Hey can anyone help me understand how to do an edit method for my
Edit: Sorry guys, I got the issue, Misspelled class name :( Hey, I got
This extension method does not work on two separate development machines: public static string
Hey i made an Edit method to edit the content of the EmployeeStore such
Hey im having trouble with my edit method in the EmployeeStore. Basically im trying
hey in my screen there is a an edit field and 2 custom button
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
Hey. I've got a login form with post as method. The action goes to
Hey, I'm trying to write a loop which updates within a method at 1/60
Possible Duplicate: Do try/catch blocks hurt performance when exceptions are not thrown? Hey everyone,

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.