2-8 编程练习
import java.util.ArrayList; public class EmployeeTest { public static void main(String[] args) { //定义ArrayList对象 ArrayList<Employee> list = new ArrayList<Employee>(); //创建三个Employee类的对象 Employee y1 = new Employee(1,"张三",5000.0); Employee y2 = new Employee(2,"李四",5500.0); Employee y3 = new Employee(3,"赵六",4000.0); //添加员工信息到ArrayList中 list.add(y1); list.add(y2); list.add(y3); //显示员工的姓名和薪资 System.out.println("员工姓名 员工薪资"); for (Employee y : list) { System.out.println(y.getName()+" "+y.getSalary()); } } }
public class Employee { private int id; private String name; private double salary; 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 Employee() { } public Employee(int id, String name, double salary) { this.id = id; this.name = name; this.salary = salary; } }
95
收起
正在回答
1回答
同学你好,练习题完成的不错,很棒!继续加油!
祝学习愉快!
java工程师2020版
- 参与学习 人
- 提交作业 9400 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星