开发者

Error message "cannot find symbol"

I am quite new to java and programming. I´m using the textbook "Java how to program". I am solving an excercise (3.11 p. 136). In this excercise i am trying to get an application with two classes to print out information about a gradebook. It is supposed to print out two strings for each of the two objects of the class, with the information: "gradeBook1 course name is:CS101 Introduction to Java Programming, instructor is Donald Duck". Some other informations for gradebook 2. I am supposed to use get and set-methods, and to use a constructor. I have worked quite a lot now without managing to compile the "gradeBookTest class" which contains the main method. I get the following error message:

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() );**

The code for the two classes are the following:

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() );
    }
}

and:

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() );
    }
}

Can anyone please help me, I am stuck here?


You wrote gradebook1 in your code instead of gradeBook1.

The gradebook1 variable does not exist and that is what the compiler is telling you: cannot find symbol symbol : variable gradebook1.


Also for the instructor name:

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

You probably mean:

public void setInstructorName(String iName)
    {
    instructorName = iName ; // I swapped the variables 
    }

And in your main method, you should call:

 System.out.printf( "gradebook2 course name is: %s\n, instructor name is: ", gradeBook2.getCourseName(), gradeBook2.getInstructorName() // Change is from getInstructorname() to getInstructorName()

Using an IDE such as Eclipse, Netbeans or IntellijIDEA would help you spotting those errors


you have mistmatching cases for both the method name getInstructorname() (should be getInstructorName() ) and gradebook1 (gradeBook1).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜