java作业

java作业,第1张

java作业
import java.util.Arrays;

public class Test61 {
	
	public static void main(String[] args) {
		Gymnast gymnast = new Gymnast();
		Classes classes = new Classes();
		double[] gymnast_score_list = {94,78.5,53.1,97.4,87,96,99.7,98.1};
		double[] class_score_list = {73, 81, 52, 97, 97, 66, 78, 61, 56, 70};
		
		System.out.println("体 *** 员成绩平均值:" + gymnast.calAverage(gymnast_score_list));
		System.out.println("班级成绩平均值:" + classes.calAverage(class_score_list));
		
	}
	
}

interface Average{
	double calAverage(double list[]);
}

class Gymnast implements Average{
	
	@Override
	public double calAverage(double list[]) {
		double[] arr = null;
		double sum = 0;
		
		if (list.length>0) {
			Arrays.sort(list);
			arr = Arrays.copyOfRange(list, 1, list.length-1);
			for (int i = 0; i < arr.length; i++) {
				sum += arr[i];
			}
			
			return sum/arr.length;
		} else {
			return 0;
		}
		
	}
	
}

class Classes implements Average{
	
	@Override
	public double calAverage(double list[]) {
		double sum = 0;
		
		if (list.length>0) {
			for (int i = 0; i < list.length; i++) {
				sum += list[i];
			}
			return sum/list.length;
		} else {
			return 0;
		}
		
	}
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4969643.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存