java 编程 之【评分系统】可以计算平均成绩和最烂评委

/**
*
* @author: Kevin
* @date :2011-07-18
* @function: to mark 0-10 point to Players,and the result is delete the highest
* and the lowest, at last reserve the average marks.
*/
package com.Homework;


import java.util.Scanner;

public class MarkSystem {

//main method
public static void main(String[] args) {

Voter voter= new Voter();
System.out.println("The last mark is :"+voter.lastMark());
System.out.println("The Worst Judger is No.:"+voter.getWorst());
}

}

//-------------------------------------------

//create class Player
class Voter
{
private float[] mark =null;
private int size = 8;

//constructor
public Voter()
{
Scanner s= new Scanner(System.in);
System.out.println("请输入参加评审人数(3人以上):");
size = s.nextInt();
mark= new float[size];

for (int i=0 ;i<size;i++)
{
System.out.println("input the NO."+(i+1)+"Judger'mark");
mark[i]=s.nextFloat();
}

}

public float lastMark()
{
float lastMark= 0 ;
int minIndex =this.getLowMarkIndex();
int maxIndex =this.getHigMarkIndex();
for (int i=0 ;i<size;i++)
{
if(i!=minIndex&&i!=maxIndex)
{
lastMark += mark[i];
}
}
return lastMark/(size-2);
}
//取得最低分的编号

public int getLowMarkIndex()
{
float lowMark = mark[0];
int lowIndex = 0;

for (int i=0 ;i<size;i++)
{
if(lowMark>mark[i])
{
lowMark = mark[i];
lowIndex = i;
}
}
return lowIndex;

}
//取出最高分的编号
public int getHigMarkIndex()
{
float higMark = mark[0];
int higIndex = 0;

for (int i=0 ;i<size;i++)
{
if(higMark<mark[i])
{
higMark = mark[i];
higIndex = i;
}
}
return higIndex;

}
//取出最烂评委的编号

public int getWorst()
{float lastMark = this.lastMark();

int worstIndex = 0;
float cha =Math.abs(mark[0]- lastMark) ;
float cha2=0f;
for (int i=0 ;i<size;i++)
{
cha2 = Math.abs(mark[i]- lastMark) ;
if(cha<cha2)
{
worstIndex= i;
}
}
return worstIndex+1;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值