package com.sf._03_collections;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Test3 {

    /**
     * 创建List<Student> ,往出5个元素
     * Student name age score
     *
     * 先进行打乱顺序,抽取前3名同学
     * 看三个同学的成绩从小到大如何排序的
     * 看三个同学成绩从大道小如何进行排序的
     *
     * 把成绩最高同学替换成你自己
     *
     *
     */
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>(Arrays.asList(
                new Student("zhangsan",10,90),
                new Student("lisi",10,91),
                new Student("wangwu",10,80),
                new Student("zhaoliu",10,97),
                new Student("xiaoli",10,60)
        ));
        // 打乱顺序
        Collections.shuffle(students);
        // 抽查3名同学
        List<Student> randomStus = new ArrayList<>();
        // 添加到集合中
        for (int i = 0; i <=2; i++) {
            randomStus.add(students.get(i));
        }
        // 看集合进行升序排序
        Collections.sort(randomStus);
        System.out.println("升序排名-------------");
        for (Student stus : randomStus) {
            System.out.println(stus);
        }
        System.out.println("---------------");
        System.out.println("降序排名");
        Collections.reverse(randomStus);
        for (Student stus : randomStus) {
            System.out.println(stus);
        }
        System.out.println("------------------");
        // 要把最高分替换成你自己
        Student maxScoreStu = randomStus.get(0);
        Collections.replaceAll(randomStus,maxScoreStu,new Student("fanjialong",18,100));
        for (Student stus : randomStus) {
            System.out.println(stus);
        }

    }
}
