Not exactly sure what I am doing wrong...it is probably something simple and just being an idiot today but I have these two errors in my program and not sure what I am doing wrong
C:\Documents and Settings\Don & Diane Kruep\My Documents\Judges.java:54: averageScores(double[]) in Judges cannot be applied to (double)
average = averageScores(score);
^
C:\Documents and Settings\Don & Diane Kruep\My Documents\Judges.java:67: operator + cannot be applied to double,double[]
total = total + g;
my code is:
//import classes
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 grades 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;
//use a while loop to keep for counter from increasing when invalid entry is made
while(!done)
{
try
{
score = Double.parseDouble(dataIn.readLine());
if ((score < 0.0) && (score > 10.0)) throw new NumberFormatException();
//reasonable check
else done = true; //exit while is grade is valid
}
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, a;
for (double i = 0; i<g.length; i++);
total = total + g;
a = total / g.length;
return a;
} //end averageGrades()
} //end class
Instructions say:
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