实验四、歌手大赛

实验四、歌手大赛,第1张

CompurerAverage.java

public interface CompurerAverage {

public double average(double x[]);

}

SongGame.java

public class SongGame implements CompurerAverage{

public double average(double x[]) {

int count=x.length;

double aver=0,temp=0;

for(int i=0;i<count;i++) {

    for(int j=i;j<count;j++) {

        if(x[j]<x[i]) {

            temp=x[j];

            x[j]=x[i];

            x[i]=temp;

        }

    }

}

for(int i=1;i<count-1;i++) {

    aver=aver+x[i];

}

if(count>2)

    aver=aver/(count-2);

else

    aver=0;

return aver;

}

}

School.java

public class School implements CompurerAverage {

    public double average(double x[]) {

        double sum=0;

        for(int i=0;ii++) {

            sum=sum+x[i];

        }

        return (sum/x.length);

    }

}

Estimator.java

public class Estimator {

    public static void main(String[] args) {

    double a[]= {9.89,9.88,9.99,9.12,9.69,9.76,8.97};

 double b[]= {56,55.5,65,50,51.5,53.6,70,49,66,62,46};

    CompurerAverage computer;

    computer=new SongGame();

    double result=computer.average(a);

    System.out.printf("%n");

    System.out.printf("歌手最后得分:%5.3f\n", result);

    computer=new School();

    result=computer.average(b);

    System.out.printf("学生平均体重:%-5.2fkg", result);

    }

}

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

原文地址: http://outofmemory.cn/langs/797858.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存