该程序的重点是让用户输入三个考试成绩,然后将他们的平均成绩和字母成绩返回给他们。
它当前的编写方式给了我一个错误的“公共静态字符串 getLetterGrade..”行,我不知道为什么会这样..
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;
}