The scoring system for Java programming can calculate the average score and the worst judges

Source: Internet
Author: User

 

/**
*
* @ 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. collections;

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 ()
{
S = new partition (system. In );
System. Out. println ("Enter the number of participants (more than 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 );
}
// Obtain the lowest score number

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;

}
// Retrieve the highest score
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;

}
// Retrieve the worst judge's number

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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.