SingGame.java
public class SingGame {
public static void main(String[] args) {
Line line = new Line();
line.givePersonScore();
}
}
Line.java
public class Line {
InputScore one;
DelScore two;
ComputerAver three;
Line(){
three = new ComputerAver();
two = new DelScore(three);
one = new InputScore(two);
}
public void givePersonScore(){
one.inputScore();
}
}
ComputerAver.java
public class ComputerAver {
public void giveAver(double[] b){
double sum = 0;
for (int i = 0; i < b.length; i++) {
sum += b[i];
}
double aver = sum/b.length;
System.out.println("最终该选手的分数是: " + aver);
}
}
DelScore.java
public class DelScore {
ComputerAver computer;
DelScore(ComputerAver computer){
this.computer = computer;
}
public void doDelete(double[] a){
java.util.Arrays.sort(a); //对数组排序
System.out.println("去掉一个最高分: "+a[a.length-1]);
System.out.println("去掉一个最低分:"+a[0]);
double[] b = new double[a.length - 2];
for (int i = 1; i < a.length - 1; i++) {
b[i - 1] = a[i];
}
computer.giveAver(b);
}
}
InputScore.java
import java.util.Scanner;
public class InputScore {
DelScore del;
InputScore(DelScore del){
this.del = del;
}
public void inputScore(){
System.out.println("请输入评委数:");
Scanner read = new Scanner(System.in);
int count = read.nextInt();
System.out.println("请输入各个评委的分数:");
double[] a = new double[count];
for (int i = 0; i < count; i++) {
a[i] = read.nextDouble();
}
del.doDelete(a);
}
}