Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java switch statement <identifier> issue

The point of this program is for a user to enter three exam scores and their average and letter grade is returned to them.

The way it is currently written gives me an error for the 'public static String getLetterGrade..' line and I don't know why that is..

public class GradeProblem
{
public static void main(String[] args)
{
 char letterGrade;
 String exam1, exam2, exam3;
 double exam1Score, exam2Score, exam3Score, average; 

 exam1 = JOptionPane.showInputDialog(null, "Enter your score for Exam 1: ");
 exam1Score = Double.parseDouble(exam1.substring(0,2));
 int intExam1Score = (int)exam1Score;

 exam2 = JOptionPane.showInputDialog(null, "Enter your score for Exam 2: ");
 exam2Score = Double.parseDouble(exam2.substring(0,2));
 int intExam2Score = (int)exam2Score;

 exam3 = JOptionPane.showInputDialog(null, "Enter your score for Exam 3: ");
 exam3Score = Double.parseDouble(exam3.substring(0,2));
 int intExam3Score = (int)exam3Score;

 average = (intExam1Score + intExam2Score + intExam3Score) / 3;

 int intAvergage = (int)average;
 letterGrade = getLetterGrade(intAverage);

 System.out.println("Your average is "+average);  
 System.out.println("Your letter grade is "+letterGrade); 

 }

 private static String getLetterGrade(average)
 {
String letterGrade;
switch(intAverage/10)
{
    case 10: letterGrade = "A";
    case 9: letterGrade = "A";
              break;
    case 8: letterGrade = "B";
              break;
    case 7: letterGrade = "C";
              break;
    case 6: letterGrade = "D";
    default:
              letterGrade = "E";
}
return letterGrade;

   }
like image 649
user1837129 Avatar asked Nov 19 '12 22:11

user1837129


1 Answers

It should be

 private static String getLetterGrade(int average){

or with any datatype, and you are referring to another non exist variable in switch statement intAverage

like image 86
jmj Avatar answered Oct 22 '22 03:10

jmj