package com.lovecoding.day12.interface04_1;

public class Student implements Comparable{

    private String name;
    private int age;

    public Student() {
    }

    @Override
    public int compareTo(Object o) {

        //强制转换
        Student s =  (Student) o;
        //比较规则
        //根据名称排序 名称相同根据年龄排序
        return this.name.compareTo(s.name) == 0 ? this.age - s.age : this.name.compareTo(s.name);
    }

    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 +
                '}';
    }
}
