package com.lovecoding.day08.ex;

public class TestStudent {
    public static void main(String[] args) {
        //测试类的main中创建一个可以装3个学生对象的数组，
        //3个学生对象的信息，并且按照学生成绩排序，显示学生信息

        Student s1 = new Student();
        s1.name = "zs";
        s1.score = 90;

        Student s2 = new Student();
        s2.name = "ls";
        s2.score = 70;

        Student s3 = new Student();
        s3.name = "ww";
        s3.score = 80;

        //创建数组
        Student[] arr = {s1,s2,s3};

        //排序之前
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getInfo());
        }
        //冒泡排序
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if ( arr[j].score > arr[j+1].score ){
                    //调换位置
                    Student temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        System.out.println("----------------------------------");
        //排序之后
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getInfo());
        }
    }
}
