package homework006;
public class Worker {
private int age;
private String name;
private double salary;
public Worker() {
}
public Worker(String name, int age, double salary) {
this.name = name;
this.age = age;
this.salary = salary;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
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 void work() {
System.out.println(name + " work");
}
@Override
public String toString() {
return "Worker [age=" + age + ", name=" + name + ", salary=" + salary + "]";
}
}
package homework006;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Ls {
public static void main(String[] args) {
// TODO 自动生成的方法存根
List<Worker> list = new ArrayList<>();
list.add(new Worker("张三",18,3000));
list.add(new Worker("李四",25,3500));
list.add(new Worker("王五",22,3200));
list.add(new Worker("赵六",24,3400));
list.remove(2);
for(int i = 0;i<list.size();i++)
{
System.out.println(list.get(i));
}
Iterator<Worker> it = list.iterator();
while(it.hasNext())
{
Worker wk = it.next();
wk.work();
}
}
}
![]()