0

我需要打印用户输入的员工的详细信息。到目前为止,我能得到的只是名字。任何人都可以帮我解决这个问题吗?

员工商店

public void add(Employee employee)
{       
    map.put(employee.getEmployeeName(), employee);
}

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

用法

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"));
Store.searchByName("James O' Carroll");
4

1 回答 1

1

您正在打印密钥,而不是存储在密钥中的值。

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

假设 Employer 类定义了一个 toString() 方法。

于 2012-06-30T17:53:58.093 回答