public class CourseGrade {
public static void main(String[] args) {
int examWeight = 70;
int labWeight = 20;
int hwWeight = 10;
double examScore;
double labScore;
double hwScore;
double finalScore;
//ask Student to input scores for exam, lab, hw
IO.output("Enter your exam scores: ");
examScore = IO.inputDouble();
IO.output("Enter your lab scores: ");
labScore = IO.inputDouble();
IO.output("Enter your homework scores: ");
hwScore = IO.inputDouble();
//compute final score as the weighted sum of exam, lab, hw score
examScore = examScore * (examWeight / 100);
labScore = labScore * (labWeight / 100);
hwScore = hwScore * (hwWeight / 100);
finalScore = examScore + labScore + hwScore;
// output the final score
IO.outputln("Your final score is: "+ finalScore);
}
} 我一次又一次收到此错误:未声明的变量:IO,并且此解决方案问题在网络上不可用 我在 java 的 bluej 编辑器中运行这段代码 根据我的 io 部分只与语法有关
您需要 IO 类,其中包含多种方法来运行您的代码。 IO 类可能看起来像这样:
public class IO {
private static java.util.Scanner userIN = new java.util.Scanner(System.in);
public static void output(Object input) {
System.out.print(input);
}
public static void outputln(Object input) {
System.out.println(input);
}
public static void outputf(String input, Object[] varArgs) {
System.out.printf(input, varArgs);
}
public static String inputLine() {
return userIN.nextLine();
}
public static String inputToken() {
return userIN.next();
}
public static int inputInt() {
int i = userIN.nextInt();
userIN.nextLine(); // Consume ENTER key.
return i;
}
public static long inputLong() {
long i = userIN.nextLong();
userIN.nextLine(); // Consume ENTER key.
return i;
}
public static double inputDouble() {
double i = userIN.nextDouble();
userIN.nextLine(); // Consume ENTER key.
return i;
}
public static float inputFloat() {
float i = userIN.nextFloat();
userIN.nextLine(); // Consume ENTER key.
return i;
}
public static void inputClose() {
userIN.close();
}
// Add more methods as required....
}
与你的代码一起使用:
public static void main(String[] args) {
int examWeight = 70;
int labWeight = 20;
int hwWeight = 10;
double examScore;
double labScore;
double hwScore;
double finalScore;
//ask Student to input scores for exam, lab, hw
IO.output("Enter your exam scores: ");
examScore = IO.inputDouble();
IO.output("Enter your lab scores: ");
labScore = IO.inputDouble();
IO.output("Enter your homework scores: ");
hwScore = IO.inputDouble();
//compute final score as the weighted sum of exam, lab, hw score
examScore = examScore * (examWeight / 100d);
labScore = labScore * (labWeight / 100d);
hwScore = hwScore * (hwWeight / 100d);
finalScore = examScore + labScore + hwScore;
// output the final score
IO.outputln("Your final score is: " + finalScore);
}