老师,检查一下作业
public class Employee{ //根据需求完成Employee类的定义 private int id; private String name; private Double salary; public Employee(int id,String name,Double salary){ super(); this.id=id; this.name=name; this.salary=salary; } public int getId(){ return this.id; } public void setId(int id){ this.id=id; } public String getName(){ return this.name; } public void setName(String name){ this.name=name; } public Double getSalary(){ return this.salary; } public void setSalary(Double salary){ this.salary=salary; } } import java.util.List; import java.util.ArrayList; public class EmployeeTest { public static void main(String[] args) { //定义ArrayList对象 ArrayList list=new ArrayList(); //创建三个Employee类的对象 Employee one=new Employee(1,"张三",5000.0); Employee two=new Employee(2,"李四",5500.0); Employee three=new Employee(3,"赵六",4000.0); //添加员工信息到ArrayList中 list.add(one); list.add(two); list.add(three); //显示员工的姓名和薪资 System.out.println("员工姓名"+" "+"员工薪资"); for(int i=0;i<list.size();i++){ System.out.println(((Employee)list.get(i)).getName()+" "+((Employee)list.get(i)).getSalary()); } } }
13
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星