老师,检查一下作业
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 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积分~
来为老师/同学的回答评分吧