请为某公司员工数组中添加新的员工,以及对员工信息的维护,步骤如下:
步骤1.写一个员工类,Employee,其中包含属性员工编号 eid,员工姓名 ename,
员工年龄 eage,以及员工的工资salary,四个属性,请提供员工类所有的
构造方法与get/set方法。
步骤2.写一个测试类,实现公司员工的添加,和修改(根据编号修改),最后打印所有员工信息。
public class Employee {
private String eid;
private String ename;
private int eage;
private int salary;
public Employee(String eid,String ename,int eage,int salary){
this.eid=eid;
this.name=name;
this.eage=eage;
this.salary =salary;
}
public String getEid() {
return eid;
}
public void setEid(String eid) {
this.eid = eid;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public int getEage() {
return eage;
}
public void setEage(int eage) {
this.eage = eage;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public static void main(String args[]){
Employee e=new Employee("001","小白",22,5000);
System.out.println("姓名:"+e.getEname()+",工资:"+e.getSalary());
}
}
Employee employee=new Employee();
List<Employee> list=new ArrayList<>();
employee.setEage(12);
employee.setEid(1);
employee.setSalary(12.3);
employee.setEmname("小张");
list.add(employee);
System.out.println("输出为:");
list.forEach(System.out::println);
employee.setEage(18);
System.out.println("年龄修改后:");
list.forEach(System.out::println);