我习惯用 C++ 编写代码,但我无法弄清楚这些 Java 错误。我感谢任何帮助或建议。这是我的代码:
public class Grade {
public int inputScore() {
int testScore;
System.out.println("Welcome to the Letter Grade Converter");
System.out.println("Enter numberical grade:");
Scanner sc = new Scanner(System.in);
testScore = sc.nextInt();
return testScore;
}
public String assignLetter() {
String grade;
if (testScore >= 88) {
grade = "A";
} else if (testScore >= 80) {
grade = "B";
} else if (testScore >= 67) {
grade = "C";
} else if (testScore >= 60) {
grade = "D";
} else if (testScore >= 0) {
grade = "F";
}
return grade;
}
public String printResult() {
System.out.println("Letter grade:" + grade);
}
}
连同我的司机班:
public class GradeApp {
public static void main(String[] args) {
Grade studentGrade = new Grade(); // create student object
String choice = "y";
while (choice.equalsIgnoreCase("y")) {
studentGrade.inputScore(); //get score from user and assign it to the variable
studentGrade.assignLetter(); //assign a letter grade based on the score
studentGrade.printResult(); //display the letter grade
}
}
}
两者都不会编译。我似乎无法弄清楚为什么。
我习惯在 C++ 中使用关系运算符“::”,它将驱动程序代码引用到其他代码中的类。我想知道如何在Java中做到这一点。grade
它一直在最底部的变量以及所有testScore
实例上给我一个“找不到符号”错误。