package com.lovecoding.day18.ex02;

public class Employee  implements  Comparable<Employee>{
    //包含属性姓名（String），薪资（double），年龄（int）
    private String name;
    private double salary;
    private int age;

    public Employee() {
    }

    public Employee(String name, double salary, int age) {
        this.name = name;
        this.salary = salary;
        this.age = age;
    }


    //按照薪资比较大小，薪资相同的按照姓名的自然顺序（调用String类的compareTo方法）比较大小。
    @Override
    public int compareTo(Employee o) { //泛型不需要强转
        //用薪资
        double result  = this.salary - o.getSalary();
        //薪资相同使用姓名
        return result == 0 ? this.name.compareTo(o.getName()) : (int) result;
    }

    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 int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", salary=" + salary +
                ", age=" + age +
                '}';
    }


}
