/**标签:最烂,lastMark,java,int,编程,System,mark,float,public From: https://blog.51cto.com/u_9427273/6008298
*
* @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;
}
}