package com.sf.day13.comparableTest;

/**
 * comparable
 * 根据年龄进行比较   升序   年龄相同根据名称进行排序 unicode值
 */
public class Student implements Comparable{
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

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

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

    @Override
    public int compareTo(Object o) {
        if(o instanceof Student){  //判断两个对象的数据类型是否相等
            Student student = (Student) o;
            if(this.age != student.age){
                return this.age-student.age;
            }else {
                this.name.compareTo(student.name);
            }
        }
        return 99;
    }
}
