i need help on how to write this java program: 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:
The number of judges on the panel. The score given by each judge, in order. Use the number of judges to decide how many scores to read - do not look for a sentinel value (such as -1 or -999) to stop. Compute the average of all scores except the highest and lowest. If any score is invalid, report bad input and then ask for that judge's score again. If the number of judges is invalid, do not ask for the number again - simply report bad input and stop.
to be more specific, i am having trouble finding the smallest and largest numbers and then subtracting them in a loop..i dont know how to write code to do that
1. Sort all results using bullesort or whatever sort algorithm you want. Then only add the scores with index from 1 to n-2
2. Create 2 variables called minScore and maxScore. Set minScore to a very high value and maxScore to a low value. Loop through all scores. Compare the actual score with minSum and with maxSum. If you want, use the Math.Min method to set the minScore variable and Math.Max to set the maxScore variable. Also add the current score to the sum. When you exit the loop, subtract minScore and maxScore from the sum.
I assume that you have all numbers in an double[] array or in a ArrayList<double> Object called scores.
double minScore = Double.POSITIVE_INFINITY;
double maxScore = Double.NEGATIVE_INFINITY;
double sum = 0;
for (double score : scores) {
sum+=score;
if (minScore > score)
minScore = score;
if (maxScore < score)
maxScore = score;
}
sum-=(maxScore+minScore);