package com.itheima;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
public class WorkerTest {
public static void main(String[] args) {
LinkedList<Worker> li = new LinkedList<Worker>();
Worker w1 = new Worker("zhang3",18,3000);
Worker w2 = new Worker("li4",25,3500);
Worker w3 = new Worker("wang5",22,3200);
Worker w = new Worker("zhao6",24,3300);
li.add(w1);
li.add(w2);
li.add(w3);
//将指定元素插入此列表的开头。
li.addFirst(w);
//删除
li.remove(w3);
Iterator<Worker> it = li.iterator();
while (it.hasNext()){
Worker s = it.next();
System.out.println("姓名:"+s.getName()+","+s.getAge()+"岁,"+"工资是"+s.getSalary()+"分。");
}
}
}
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");
}
}
这样就对了。你要使用s.getName;s.getSalary;s.getAge方法 |