Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Overview For this assignment, you will develop Java programs to solve several pr

ID: 671982 • Letter: O

Question

Overview

For this assignment, you will develop Java programs to solve several problems. You will also write test cases with which to test those programs. It is very important that you spell and capitalize the names of the programs exactly as they are given in this assignment. It is also very important that you submit your test cases as a plain-text file called assign2.txt.

You will need the IO module to read input from the keyboard and to generate output in a form that our grading program can understand. Do not modify or hand in the IO module. If you know some Java already, you may use advanced features that we have not covered in class yet (though it is not necessary to do so). However, you may NOT use any modules or classes from outside java.lang (do not add any "import" statements to your programs). YOU MUST USE THE IO MODULE TO OUTPUT ALL ANSWERS. Read the document referenced above. Error conditions

For this assignment, when you detect an error condition, call IO.reportBadInput() and ask for the input again.

Problem 1 Write your code in the file Scores.java. Write your test cases in assign2.txt.

In many Olympic sports, an athlete is given scores by a panel of judges. Scores can range from 0.0 (awful) to 10.0 (perfect). To ensure fairness, the highest and lowest scores are dropped, and the remaining scores are averaged to produce the athlete's overall score.

Ask the user for the following information, in this order:

1.The number of judges on the panel (an integer).

2.The score given by each judge, one by one (real numbers).

Compute the average of all scores except the highest and lowest (a real number). If two or more judges give the same lowest score, only one should be dropped (the same principle applies to ties for the highest score).

Example:

java Scores

4 [this is the number of judges, not a score]

-4.3 User entered bad input.

3.7

4.9

11.0 User entered bad input.

10.5 User entered bad input.

10.0

4.3

RESULT: 4.6

Explanation / Answer

public class scores1 {
public static void main(String []args){
double max=0.0; //just set max to the lowest value possible
double min=10.0; //and initialize min with the highest value possible
double numScore; //Declare numScore at the beginning
double sum=0; //We will sum up all inputs, subtract min and max at the end and divide it by NumJudges-2.
int NumJudges = IO.readInt();
if (NumJudges < 3){ //You need at least 3 judges - else there wouldn't be any values
IO.reportBadInput();
}

for (int x=0;x<NumJudges;x++) //As long as x is lower than the number of judges the loop will run -> one run for every judge
{
System.out.println("Enter your score:");
numScore = IO.readDouble();
if (numScore > 10 || numScore < 0){ //You can use || as an 'OR'
IO.reportBadInput();
break;
}


if (numScore < min){ //If the input is smaller than min, we have got a new min value
min = numScore;
}
if (numScore > max){ //If the input is bigger than max, we have got a new max value
max = numScore;
}

sum=sum+numScore; //Sum up all the inputs in the loop one by one
}
sum=(sum-min-max)/(NumJudges-2); //In the end we subtract min & max from the sum and divide the whole thing by the number of judges (minus the min and the max judge)
System.out.println(sum);
}

}