我们的作业目标是在两个不同的班级(学生,成绩)中实现 3 名学生的成绩,并找到我到目前为止的平均成绩,
public class Program01
{
public static void main(String[] args)
{
Student bob, john, matt;
Grades grades;
grades = new Grades();
double bobgrade, johngrade, mattgrade;
bob = new Student();
john = new Student();
matt = new Student();
bob.setup();
john.setup();
matt.setup();
bob.display();
john.display();
matt.display();
bobgrade = bob.overallGrade();
johngrade = john.overallGrade();
mattgrade = matt.overallGrade();
grades.average(bobgrade, johngrade, mattgrade);
System.out.println("The overall grade for the class is: " + grades.theSectionAverage);
}
public class Student
{
Grades grades;
String fullName, firstName, lastName, name;
int studentProgramGrade, studentExamGrade;
public void setup(){
setName();
setGrades();
}
public void setName()
{
System.out.print("Please, enter the student's name in the form of Doe, John or Smith, Jane:");
fullName = Keyboard.readString();
firstName = fullName.substring(fullName.indexOf(" ") + 1, fullName.length());
lastName = fullName.substring(0, fullName.indexOf(","));
name = firstName + " " + lastName;
}
public void setGrades()
{
studentExamGrade = grades.setupExam(name);
studentProgramGrade = grades.setupProgram(name);
}
public void display()
{
System.out.println(name + " " + grades.display());
}
public double overallGrade()
{
final double PROGRAM_WEIGHT = 0.40;
final double EXAM_WEIGHT = 1 - PROGRAM_WEIGHT;
double theOverallGrade;
theOverallGrade = studentProgramGrade * PROGRAM_WEIGHT + studentExamGrade * EXAM_WEIGHT;
return theOverallGrade;
}
}
public class Grades {
int programGrade, examGrade;
double theSectionAverage;
public int setupExam(String studentname)
{
System.out.print("Please, enter the exam grade for " + studentname + ":");
examGrade = Keyboard.readInt();
return examGrade;
}
public int setupProgram(String studentname)
{
System.out.print("Please, enter the program grade for " + studentname + ":");
programGrade = Keyboard.readInt();
return programGrade;
}
public String display()
{
return programGrade + " " + examGrade;
}
public double average(double bobgrade, double johngrade, double mattgrade)
{
theSectionAverage = bobgrade + johngrade + mattgrade / 3;
return theSectionAverage;
}
}
每当我尝试运行它时,我都会收到此错误:
线程“main”java.lang.Error 中的异常:未解决的编译问题:无法解析键盘
at Student.setName(Student.java:18)
at Student.setup(Student.java:10)
at Program01.main(Program01.java:19)
任何帮助将不胜感激。