求JAVA评委打分代码

求JAVA评委打分代码,第1张

正好我闲着,给你写一个吧。

我写的这个评委分数是在代码里固定到数组里了,如果你需要运行时手动输入评分,可以将oldScores里的数据改成手动输入就行了(这个不用我再写了吧,如果不会再追问,再告诉你)。

你先新建一个类,将下面的main方法全部复制进去就启答能运行了,自己看一下吧。

/** 主方法 */

    public static void main(String[] args)

    {

        /** 保存原始评分的数组(如果你需要运行时手动输入分数,将 oldScores中的数据改成手动输入就行了 */

        double[] oldScores = {15, 77, 55, 88, 79, 98, 67, 89, 68, 88}

        /** 最终将用悄答慧来保存排序后的数组 */

        double[] scores = new double[oldScores.length]

        double temp

        /** 平均分 */

        double avg = 0

        int k

        

        /** 将原始评分放入最终排序数组 */

        for (int i = 0 i < oldScores.length i++)

        {

            scores[i] = oldScores[i]

        }

        

        /** 开始排序 */

        for (int i = 0 i < scores.length - 1 i++)

        {

            k = i

            for (int j = i + 1 j < scores.length j++)

            {

                if (scores[k] < scores[j])

                {

                    k = j

                }

            }

            if (i != k)

            {

                temp = scores[k]

                scores[k] = scores[i]

                scores[i] = temp

            }

        }

        

        /** 计算去掉最高分和最低分之后的和 */

        double sum = 0

        /** 记录计算平均分的分数个数 */

        double num = 0

        for (int i = 1 i < scores.length - 1 i++)

        {

            num++

            sum += scores[i]

        }

        /** 计算平均分 */

        avg = sum / num

        

        /** 最公平的肯定不是在scores数组两端 */

        double zgp = 0

        double cha = 0

        /** 标记与平均值差值最小的分数位置 */

        int flag = 0

        /** 开始寻找最公平评分 */

        for (int i = 1 i < scores.length - 1 i++)

        {

            /** 为cha赋初始值,注意比较差值要使用绝对值比较 */

            if (i == 1)

            {

                cha = Math.abs(scores[i] - avg)

            }

            double cha1 = Math.abs(scores[i] - avg)

            if (cha1 < cha)

            {

                cha = cha1

                flag = i

            }

        }

        zgp = scores[flag]

        

        /** 由于最不公平的分数肯定在scores数组的第一个或者是最后一个 */

        double bgp = 0

        if (Math.abs(scores[0] - avg) > Math.abs(scores[scores.length - 1] - avg))

        {

            bgp = scores[0]

        }

        else

        {

            bgp = scores[scores.length - 1]

        }

        

        /** 全部计算完成,下面开始输出结果 */

        System.out.println("原始评委分数如下:")

        for (int i = 0 i < oldScores.length i++)

        {

            System.out.print(oldScores[i] + ", ")

        }

        System.out.println()

        

        System.out.println("排序后分数如下:")

        for (int i = 0 i < scores.length i++)

        {

            System.out.print(scores[i] + ", ")

        }

        System.out.println()

        

        System.out.println("去掉最高分和最低分后平均分举闷:" + avg)

        System.out.println("最公平分数:" + zgp)

        System.out.println("最不公平分数:" + bgp)

    }

import java.text.DecimalFormat

import java.util.Arrays

import java.util.Scanner

public class Test {

public static void main(String[] args) {

System.out.println("链核最后总分为:"+input())}

private static String input()

{

Scanner input=new Scanner(System.in)

float[] score=new float[8]

for(int i=0i<8i++)

{

System.out.print("第"+(i+1)+"枝裂位裁判分数:猛唤闭")

score[i]=input.nextFloat()

}

sort(score)

return display(score)

}

private static void sort(float[] score)

{

Arrays.sort(score)

}

private static String display(float[] score)

{

DecimalFormat df=new DecimalFormat("#.00")

double sum=0

for(int i=1i<score.length-1i++)

{

sum+=score[i]

}

return df.format(sum)

}

}

感觉上面的答案有点不是为这个题目专门提供的,有很多不是很需要的代码。

另外用接口编写,很显然,所有的学生,教师,裁判都可以用person接口,住宿和吃饭问题就是接口里面的方法。

interface Person{

    public void Stay()

    public 庆码void eat()

}

class Student implements Person{

    public void Stay() {

        System.out.println("住在学生宿舍")

    }

    public void eat() {

        System.out.println("在学生食堂吃冲差悔饭")

    }    

}

class Teacher implements Person{

    public void Stay() {

     散正   System.out.println("住在教师公寓")

    }

    public void eat() {

        System.out.println("在教师食堂吃饭")

    }    

}

class Judge implements Person{

    public void Stay() {

        System.out.println("住在宾馆")

    }

    public void eat() {

        System.out.println("在宾馆吃饭")

    }    

}


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

原文地址: https://outofmemory.cn/yw/12535144.html

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

发表评论

登录后才能评论

评论列表(0条)

保存