I have writing a program with a few errors...One thing I am having trouble with is figuring out arrays....also I am trying to get the min and max value figured out using the math function and for loop but havin an awful time trying to figure this out...
my code is:
import java.io.*;
public class Judges
{
public static void main(String[] args) throws IOException
{
//declaring variables
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
float average;
double score = 0.0;
boolean done = false;
//Get input from user for scores and assign them to an array
for (double i = 0; i <= 8; i++)
{
System.out.print("Enter score # 1:");
System.out.print("Enter score # 2:");
System.out.print("Enter score # 3:");
System.out.print("Enter score # 4:");
System.out.print("Enter score # 5:");
System.out.print("Enter score # 6:");
System.out.print("Enter score # 7:");
System.out.print("Enter score # 8:");
done = false;
while(!done)
{
try
{
score = Double.parseDouble(dataIn.readLine());
if ((score < 0.0) && (score > 10.0)) throw new NumberFormatException();
//reasonable check
else done = true;
}
catch(NumberFormatException e)
{
System.out.print("** Invalid Entry ** \nPlease re-enter score");
}
} //end while
} //end for
//call a method to calculate the average
average = averageScores(score);
//Display grades and average
System.out.println("");
System.out.println("The average grade is " + average);
} //end main
//method used to calculate the average
public static double averageScores(double[] g)
{
double total = 0.0;
double a = 0.0;
for (double i = 0; i < g; i++)
{
total = total + g;
a = total / g;
System.out.println("The maxiumum score is " + max_score);
System.out.println("The minimum score is " + min_score);
System.out.println("The total score is " + total);
return a;
}
} //end averageScores()
} //end class
instructions are:
Arrays and For loops
In a diving competition, each contestant’s score is calculated by dropping the lowest and highest scores and then adding the remaining scores. Write a program (Judges.java) that allows the user to enter 8 judges’ scores into an array of doubles and then outputs the points earned by the contestant.
1. you can create either a command prompt console application or a console application using dialog boxes for this program
2. accept the user input as an array of doubles… accept 8 scores
3. only accept scores between 1.0 and 10.0 (include the endpoints)
4. make sure your user is entering valid scores only… if an invalid entry is made, prompt them with an error message and allow them to re-enter that score
5. in your prompt to the user (whether it is the original prompt or the prompt after an invalid entry was made), identify the number of the score they are entering (e.g., Enter score # 5
6. calculate the minimum and maximum scores using the functions from the Math class described in Chapter 3. (HINT: you can use these functions in a for loop to compare two numbers at a time to determine which is the max (or min))
7. calculate the total (the sum of the remaining 6 scores)
8. display the min, max, and total formatting each to two decimal places
Example:
Enter score # 1: 9.2
Enter score # 2: 9.3
Enter score # 3: 9.0
Enter score # 4: 9.9
Enter score # 5: 9.5
Enter score # 6: 9.5
Enter score # 7: 9.6
Enter score # 8: 9.8
The maximum score is 9.90
The minimum score is 9.00
The total score is 56.90
I am completely stuck and any help id really really appreciate