I can't get this to compile. It is for a homework assignment. The program asks user for 5 test scores and is to display letter grade and average test score. I was able to get the calcAverage method to work, but after adding the determineGrade method, I end up with errors.
Could you please lend some assistance to help me solve this? THX in advance!
import javax.swing.JOptionPane; //Needed for dialog boxes
import java.io.*;
public class TestGradeAvg
{
public static void main(String [] args) throws IOException
{
String input;
double total;
int gradeCounter;
double score;
double avgScore;
//initialize
total = 0;
gradeCounter = 1;
//process / get user score
while (gradeCounter <= 5)
{
input = JOptionPane.showInputDialog("Enter score.");
score = Double.parseDouble(input);
total = total + score;
gradeCounter = gradeCounter + 1;
}
//Main method calling calcAverage(avgScore);
calcAverage(avgScore);
avgScore = total / 5.0;
//Main method calling determineGrade method
char grade = determineGrade(score);
//determineGrade method (based on input)
}
public static char determineGrade(double score)
{
if (score >= 90.0) { return 'A'; }
else if (score >= 80.0) { return 'B'; }
else if (score >= 70.0) { return 'C'; }
else if (score >= 60.0) { return 'D'; }
else {
return 'F';
JOptionPane.showMessageDialog(null, "Your grade is " + grade);
}
//calcAverage method
}
public static void calcAverage(double avgScore)
{
JOptionPane.showMessageDialog(null, "Your average score is " + avgScore);
}
}