我对Java和编程很陌生。我正在使用教科书“Java如何编程”。我正在解决一项练习(3.11第136页)。在本练习中,我试图获得一个具有两个类的应用程序,以打印出有关成绩簿的信息。应该为该类的两个对象的每一个打印两个字符串,并带有以下信息:“gradeBook1类(class)名称为:CS101 Java编程简介,指导老师为Donald Duck”。有关成绩簿2的其他一些信息。我应该使用get和set方法,并使用构造函数。我现在已经做了很多工作,而没有设法编译包含main方法的“gradeBookTest类”。我收到以下错误消息:

aGradeBookTest.java:8: cannot find symbol
symbol  : variable gradebook1
location: class aGradeBookTest
    System.out.printf( "gradeBook1 course name is: emphasized text%s,\n instructor is %s\n", gradeBook1.getCourseName(), gradebook1.getInstructorName() );
                                                                                                          ^
aGradeBookTest.java:9: cannot find symbol
symbol  : method getInstructorname()
location: class aGradeBook
    System.out.printf( "gradebook2 course name is: %s\n, instructor name is: ", gradeBook2.getCourseName(), gradeBook2.getInstructorname() );**

这两个类的代码如下:
public class aGradeBook
{
    private String courseName;
    private String instructorName;

    public aGradeBook( String name, String iName )
    {
        courseName = name;
        instructorName = iName;
    }

    public void setCourseName( String name )
    {
        courseName = name;
    }

    public String getCourseName()
    {
        return courseName;
    }

    public void setInstructorName(String iName)
    {
        iName = instructorName;
    }

    public String getInstructorName()
    {
        return instructorName;
    }

    public void displayMessage()
    {
        System.out.printf ("Welcome to the gradebook for\n%s!\n", getCourseName() );
    }
}

和:
public class aGradeBookTest
{
    public static void main( String[]args )
    {
        aGradeBook gradeBook1 = new aGradeBook( "CS101 Introduction to Java Programming", "Donald Duck" );
        aGradeBook gradeBook2 = new aGradeBook( "CS102 Data structures in Java", "Tom & Jerry" );

        System.out.printf( "gradeBook1 course name is: %s,\n instructor is %s\n", gradeBook1.getCourseName(), gradebook1.getInstructorName() );
        System.out.printf( "gradebook2 course name is: %s\n, instructor name is: ", gradeBook2.getCourseName(), gradeBook2.getInstructorname() );
    }
}

有人可以帮我吗,我被困在这里吗?

最佳答案

您在代码中写了gradebook1而不是gradeBook1
gradebook1变量不存在,这是编译器告诉您的:cannot find symbol symbol : variable gradebook1

10-04 10:14