作业

2016-01-14  本文已影响0人  凹特曼
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Worker {
    private int age;
    private String name;
    private double salary;

    public Worker() {

    }

    public static void main(String[] args) {
        List<Worker> workers = new ArrayList<Worker>();
        workers.add(new Worker("zhang3",18,3000));
        workers.add(new Worker("li4",25,3500));
        workers.add(new Worker("wang5",22,3200));
        workers.add(2,new Worker("zhao6",24,3300));
        workers.remove(3);
        for (Worker worker : workers) {
            System.out.println("Name:"+worker.getName()+"Age:"+worker.getAge()+"Salary:"+worker.getSalary());
        }

        Iterator iterator = workers.iterator();
        while(iterator.hasNext()){
            Worker worker =(Worker) iterator.next();
            System.out.println("Name:"+worker.getName()+"Age:"+worker.getAge()+"Salary:"+worker.getSalary());
        }
    }

    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");
    }

    public String toString(){
        return name + " " + age + " " + salary;
    }

    public boolean equals(Worker w){
        if(!w.name.equals(name)){
            return false;
        }

        if(w.age != age){
            return true;
        }

        if(w.salary != salary){
            return true;
        }
        return true;
    }
}
上一篇 下一篇

猜你喜欢

热点阅读