java作业 流水线

计算平均分

package javawork;


public class AveClass {

public void aveScore(double [] score){
double ave=0d;
for(int i=0;iave+=score[i];
}
ave/=score.length;
System.out.println("平均分:"+ave);
}
}

从小到大排序,去掉一个最高分,去掉一个最低分

package javawork;


import java.util.Arrays;


public class RevClass {
AveClass ave;
public RevClass(AveClass ave){
this.ave = ave;
}
public void delScore(double[] score){
Arrays.sort(score);
for(int i=0;iSystem.out.println(score[i]);
}
double score2[] = new double[score.length-2];
System.out.println("去掉一个最高分:"+score[score.length-1]);
System.out.println("去掉一个最低分:"+score[0]);
System.out.println("剩余得分:");
for(int i=1;iscore2[i-1]=score[i];
System.out.println(score2[i-1]);
}
ave.aveScore(score2);
}
}

输入打分教练人数,输入分数。

package javawork;


import java.util.Scanner;


public class ScoreClass {
RevClass rev;
public ScoreClass(RevClass rev){
this.rev = rev;
}
public void scannerScore(){
Scanner sc = new Scanner(System.in);
System.out.println("(要求裁判大于两人)请输入裁判人数:");
int num = sc.nextInt();
double score[] = new double[num];
for(int i=0;iSystem.out.println("教练"+(i+1)+"请打分:");
score[i] = sc.nextDouble();
}
rev.delScore(score);
}

}

流水线类,实现动态打分

package javawork;


public class WaterClass {
AveClass ac ;
RevClass rc ; 
ScoreClass sc;
public WaterClass(){
ac = new AveClass();
rc= new RevClass(ac);
sc = new ScoreClass(rc);
}

public void basketScore(){
sc.scannerScore();
}

}

主函数

package javawork;


public class Main {
public static void main(String[] args) {
WaterClass wc = new WaterClass();
wc.basketScore();
}
}

你可能感兴趣的:(java课堂作业)