62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.ArrayList;
class Employee {
private String name;
private float salary;
private String idno;
// public Object getIdno;
public Employee(String name, float salary, String idno) {
this.name = name;
this.salary = salary;
this.idno = idno;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setSalary(float salary) {
this.salary = salary;
}
public float getSalary() {
return salary;
}
public void setIdno(String idno) {
this.idno = idno;
}
public String getIdno() {
return idno;
}
}
class Employer {
// ArrayList al = new ArrayList();
ArrayList<Employee> al = null;
public Employer() {
al = new ArrayList<Employee>();
}
public void addemp(Employee emp) {
al.add(emp);
}
public void show_info(String idno) {
for (int i = 0; i < al.size(); i++) {
Employee employee = al.get(i);
if (employee.getIdno().equals(idno)) { //这里进行了修改
System.out.println("该员工的信息是:" + employee.getName() + " "
+ employee.getIdno() + " " + employee.getSalary());
}
}
}
}
public class Array_List {
public static void main(String[] args) {
Employee emp1 = new Employee("maozedong", 1000, "SB001");
Employer eeeee = new Employer();
eeeee.al.add(emp1);
eeeee.show_info("SB001");
System.out.println("第1个人的信息:" + emp1.getName() + " ;" + emp1.getIdno()
+ " ;" + emp1.getSalary());
}
}