public class StaffRecruit implements IAverage {
@Override
public double average(double[] x) {
// 去掉一个最高分和一个最低分
double sum = 0;
double max = max(x);
double min = min(x);
for (double num : x) {
if (num != max && num != min) {
sum += num;
}
}
return sum / (x.length - 2);
}
}
public class FinalExam implements IAverage {
@Override
public double average(double[] x) {
// 计算全班同学的平均分
double sum = 0;
for (double num : x) {
sum += num;
}
return sum / x.length;
}
}
public class Main {
public static void main(String[] args) {
double[] interviewScores = {80, 90, 85, 95, 70, 75, 88};
double[] examScores = {80, 90, 85, 95, 70, 75, 88, 92, 87, 78, 83, 79, 88, 91, 86, 82, 89, 84, 80, 85};
StaffRecruit staffRecruit = new StaffRecruit();
double averageInterviewScore = staffRecruit.average(interviewScores);
System.out.println("工作人员招聘的面试成绩平均分:" + averageInterviewScore);
FinalExam finalExam = new FinalExam();
double averageExamScore = finalExam.average(examScores);
System.out.println("某个科目的考试成绩平均分:" + averageExamScore);
}
}