编辑代码

package other;
//实现员工信息类Employee
public class Employee {
	//成员变量:编号id(int)
	private int id;
	//姓名name(String)
	private String name;
	//薪资salary(double)
	private double salary;
	//方法:构造方法
	public Employee(int id, String name, double salary) {
		super();
		this.id = id;
		this.name = name;
		this.salary = salary;
	}
	public Employee() {
		
	}
	//相关的get和set方法
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getSalary() {
		return salary;
	}
	public void setSalary(double salary) {
		this.salary = salary;
	}
	
	
}
}
public class EmployeeTest {
	public static void main(String[] args) {
	  
		List<Employee> list = new ArrayList<Employee>();
        //创建三个Employee类的对象
		Employee emp1 = new Employee(1,"张三",5000);
		Employee emp2 = new Employee(2,"李四",5500);
		Employee emp3 = new Employee(3,"赵六",4000);
        //添加员工信息到ArrayList中
		list.add(emp1);
		list.add(emp2);
		list.add(emp3);
        //显示员工的姓名和薪资
		System.out.printf("员工姓名          ");
        System.out.printf("员工薪资");
        System.out.println();
        //foreach增强型循环输出内容
        for (Employee emp:list) {
            System.out.print(((Employee)emp).getName() + "                 ");
            System.out.print(((Employee)emp).getSalary());
            System.out.println();
        }
    }
}