我需要打印用户输入的员工的详细信息。到目前为止,我能得到的只是名字。任何人都可以帮我一把吗?
EmployeeStore
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");
答案 0 :(得分:1)
您正在打印密钥,而不是密钥中存储的值。
public Employee searchByName(String name)
{
Employee employee = map.get(name);
System.out.println(employee.toString());
return employee;
}
假设Employer类已定义了toString()方法。