package com.lovecoding.day12.interface04_2;

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

        //单独比较两个对象
        PersonCompator personCompator = new PersonCompator();
        System.out.println(personCompator.compare(arr[0], arr[1]));

        for (Person person : arr) {
            System.out.println(person);
        }

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

        for (Person person : arr) {
            System.out.println(person);
        }

    }
}
