package _06_综合练习;

import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        /**
         * 	在唱歌比赛中，
         * 	有6名评委给选手打分，分数范围是[0 - 100]之间的整数。
         * 	选手的最后得分为：去掉最高分、最低分后的4个评委的平均分，
         * 	请完成上述过程并计算出选手的得分。
         */
        double[] scores = getScores();

        for (int i = 0; i < scores.length; i++) {
            System.out.print (scores[i]+" ");
        }

        // 求分数最大值
        double min =getMin(scores);
        // 求分数最小值
        double max =getMax(scores);
        // 用总和-max-min / 4
        double sum = getSum(scores);

        double lastScore = (sum - max -min) / 4;
        System.out.println("最后分数为:"+ lastScore);
    }

    private static double getSum(double[] scores) {
        double sum = 0;
        for (double score : scores) {
            sum+=score;
        }
        return sum;
    }
    private static double getMax(double[] scores) {
        double max = scores[0];
        for (int i = 0; i < scores.length; i++) {
            if(scores[i]> max){
                max = scores[i];
            }
        }
        return max;
    }
    private static double getMin(double[] scores) {
        double min = scores[0];
        for (int i = 0; i < scores.length; i++) {
            if(scores[i]< min){
                min = scores[i];
            }
        }
        return min;
    }

    public static double[] getScores() {
        Scanner scanner = new Scanner(System.in);
        double[] scores = new double[6];
        for (int i = 0; i < scores.length; ) {
            System.out.println("请录入选手分数");
            double score = scanner.nextDouble();
            if(score >=0  && score <=100){
                scores[i] = score;
                i++;
            }else{
                System.out.println("分数不合理 必须在[0-100]区间");
            }
        }

        return scores;
    }
}
