package com.lovecoding.day12.interface04_1;

public class TestStudent {
    public static void main(String[] args) {
        Student[] arr = new Student[5];
        arr[0] = new Student("a",90);
        arr[1] = new Student("c",90);
        arr[2] = new Student("e",71);
        arr[3] = new Student("d",92);
        arr[4] = new Student("b",95);

        //单独比较两个对象
        System.out.println(arr[0].compareTo(arr[0]));
        System.out.println(arr[1].compareTo(arr[2]));
        System.out.println(arr[2].compareTo(arr[2]));

        System.out.println("所有学生：");
        for (Student student : arr) {
            System.out.println(student);
        }

        System.out.println("按照学号排序：");
        for (int i = 1; i < arr.length; i++) {
            for (int j = 0; j < arr.length-i; j++) {
                if(arr[j].compareTo(arr[j+1])>0){
                    Student temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}
