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

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
/**
*
* @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
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;
}
}
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: Java