h.contains(id) 怎么没有用啊 哪位大神帮忙看看
package work1;import java.util.*;
public class TestEmployee {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
HashSet h=new HashSet();
do {
System.out.println("请选择:1.添加员工 2.显示信息 3.按姓名查询");
int select = sc.nextInt();
if (select == 1) {
System.out.println("请输入姓名:");
String name = sc.next();
System.out.println("请输入工资金额:");
double salary = sc.nextDouble();
String id;
do {
System.out.println("请输入员工号:");
id = sc.next();
if(h.contains(id)){ //******************
break;
} else {
System.out.println("此员工号已存在,请重新输入!");
}
} while (true);
Employee emp = new Employee(name, id, salary);
h.add(emp);
} else if (select == 2) {
Iterator it=h.iterator();
while(it.hasNext()){
System.out.println(it.next().toString());
}
} else if (select == 3) {
} else if (select == 0) {
break;
} else {
}
} while (true);
}
}
//*******************************************************
public class Employee {
private String name;
private String id;
private double salary;
public Employee(String name, String id, double salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public String toString() {
return "姓名:" + name+" 工号:" + id + " 工资:" + salary;
}
}