我正在努力制作一个简单的成绩册计划。我的代码尚未完成,但我首先尝试构建它。我一直得到一个未解决的编译错误,对于我的生活我无法弄清楚。我知道这是一件简单而愚蠢的事情,但我和你的新人差不多。任何试图克服此错误的帮助(Exception in thread "main" java.lang.Error: Unresolved compilation problem: student cannot be resolved to a variable
)都会非常感激!
import java.util.Scanner;
public class Gradebook {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
float discussionweight, hwweight, examweight, discussion, hw, exam, finalaverage;
// Initializes the input scanner
Scanner scan = new Scanner(System.in);
System.out.print("Enter the students name: ");
student = scan.next("");
// Prompts for the weight of the discussions
System.out.print ("Enter the weight of the discussions as an integer: ");
discussionweight = scan.nextFloat();
// Prompts for the discussions grade
System.out.print ("Enter the score of the discussions as an integer: ");
discussion = scan.nextFloat();
// Prompts for the weight of the homework grade in an integer
System.out.print ("Enter the weight of the homework as an integer: ");
hwweight = scan.nextFloat();
// Prompts for hw grade
System.out.print ("Enter the hw grade: ");
hw = scan.nextFloat();
System.out.print("Enter the weight of the exam as an integer");
examweight = scan.nextFloat();
System.out.print("Enter the exam grade");
exam = scan.nextFloat();
// Calculate and print the final, weighted average.
finalaverage = (((discussionweight * discussion) + (hw * hwweight) + (exam * examweight)) / 100);
System.out.println ("The final average is "+ finalaverage);
}
}
}
}
答案 0 :(得分:1)
看起来你永远不会声明一个名为student的变量。
string student = scan.next("");
与您正在使用的其他变量相同。
答案 1 :(得分:0)
student = scan.next("");
你永远不会告诉编译器学生是什么类型。
像String student = scan ...
之类的东西