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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:34:07+00:00 2026-06-06T20:34:07+00:00

I have looked online and i havent been able to fix a problem that

  • 0

I have looked online and i havent been able to fix a problem that i am having. I am making an employee store using a hashMap but im not sure whether i am supposed to print the toString() or the theEntry.getKey() as i have in my current version. When using the getKey() method i am getting the wrong output which is:

*Employee’s in the Company.***
Employee Name: James O’ Carroll
Employee Id: James O’ Carroll
E-mail: James O’ Carroll

As you can see in the MainApp i want Store.add(new Employee (“James O’ Carroll”, 18,”hotmail.com”)); to be the output.

I will paste my code:

//MainApp.
public class MainApp
{

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

    }
    public void start()
    {
        EmployeeStore Store = new EmployeeStore();
        Store.add(new Employee ("James O' Carroll", 18,"hotmail.com"));
        Store.print();

    }

}

//Employee
//Imports:

//********************************************************************
//Employee Class.
public class Employee
{
//Variables.
    private String employeeName;
    private int employeeId;
    private String employeeEmail;
//********************************************************************  
//Constructor.
    public Employee(String employeeName, int employeeId, String employeeEmail) 
    {
        this.employeeName = employeeName;
        this.employeeId = employeeId;
        this.employeeEmail = employeeEmail;
    }
//********************************************************************
//Getters.
    public String getEmployeeEmail() {
        return employeeEmail;
    }
    public void setEmployeeEmail(String employeeEmail) {
        this.employeeEmail = employeeEmail;
    }
    public String getEmployeeName() {
        return employeeName;
    }
    public int getEmployeeId() {
        return employeeId;
    }
//********************************************************************
//toString method.
    public String toString() {
        return "Employee [employeeName=" + employeeName + ", employeeId="
                + employeeId + ", employeeEmail=" + employeeEmail + "]";
    }
//********************************************************************





}

//EmployeeStore.
//Imports.
import java.util.HashMap;
//********************************************************************
import java.util.Map;

public class EmployeeStore 
{
    HashMap<String, Employee> map;

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

        map.put(obj.getEmployeeName(), obj);
    }
//********************************************************************
//Remove from the Hashmap : Employee.
    public void remove(String key)
    {
      //Remove the Employee by name.
        map.remove(key);
    }
//********************************************************************
//Print the Hashmap : Employee. 
    public void print()
    {
        System.out.println("\n********Employee's in the Company.********");
        for(Map.Entry<String, Employee> theEntry : map.entrySet())
        {
            System.out.println("Employee Name:\t" + theEntry.getKey());
            System.out.println("Employee Id:\t" + theEntry.getKey());
            System.out.println("E-mail:\t "+ theEntry.getKey());

        }
    }


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


}
  • 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-06T20:34:08+00:00Added an answer on June 6, 2026 at 8:34 pm

    This is clearly wrong:

    for(Map.Entry<String, Employee> theEntry : map.entrySet())
    {
        System.out.println("Employee Name:\t" + theEntry.getKey());
        System.out.println("Employee Id:\t" + theEntry.getKey());
        System.out.println("E-mail:\t "+ theEntry.getKey());
    }
    

    You’re printing the same value three times – how could it be the name, ID and email address? You’re printing the key from the entry, which is always the name. You want the value of the entry.

    You want this:

    // This assumes you've renamed all the properties in Employee to be more
    // sensible - there's no point in including the "employee" part - we already
    // know we're calling a method on Employee
    for (Employee employee : map.values())
    {
        System.out.println("Employee Name:\t" + employee.getName());
        System.out.println("Employee Id:\t" + employee.getId());
        System.out.println("E-mail:\t "+ employee.getEmail());
    }
    

    (Or just print employee of course. It depends on what you want the output to be.)

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

Sidebar

Related Questions

I have looked online but was unable to find the difference between using @Url.Content
I have looked online about this. So my understanding is that AdapterContextMenuInfo.position is the
This is for homework but please know that I have looked online for help
Have looked quite hard for this answer but having no luck. I have 3
I have looked at many other threads that show how to use accelerometer values,
Newbie question about JavaFX that I haven't been able to answer, despite knowing it
I have looked online and in my books but I can't seem to get
I'm rather new to bash and a few others, and I have looked online
Using the GUI guide editor in Matlab 2008b, I have run into a problem
I have looked online for what this exception means in relation to my program

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.