在我的代码中,我需要它来接受字母等级,然后它会打印出相应的数字值。我遇到的问题是我无法弄清楚如何正确地调用方法。我觉得我很接近,但对于做什么很困惑。
public class Grade
{
public static void main( String[ ] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a letter grade: ");
String letterGrade = input.nextLine();
Grade number = new Grade(letterGrade);
double grade = number.getNumericGrade();
System.out.println("The numberic value is: "
+ grade);
}
public double getNumericGrade(String letterGrade)
{
double numericGrade = 0.0;
if ((letterGrade == "A") || (letterGrade == "A+"))
numericGrade = 4.0;
else if (letterGrade == "A-")
numericGrade = 3.7;
else if (letterGrade == "B+")
numericGrade = 3.3;
else if (letterGrade == "B")
numericGrade = 3.0;
else if (letterGrade == "B-")
numericGrade = 2.7;
else if (letterGrade == "C+")
numericGrade = 2.3;
else if (letterGrade == "C")
numericGrade = 2.0;
else if (letterGrade == "C-")
numericGrade = 1.7;
else if (letterGrade == "D+")
numericGrade = 1.3;
else if (letterGrade == "D")
numericGrade = 1.0;
else if (letterGrade == "D-")
numericGrade = 0.7;
else if (letterGrade == "F")
numericGrade = 0.0;
else
numericGrade = -1;
return numericGrade;
}
}