このプログラムのポイントは、ユーザーが3つの試験のスコアを入力し、それらの平均と文字のグレードが返されることです。Java switch文<identifier> issue
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;
}
パラメータ "average"のデータ型がありません –