可以找到错误

时间:2014-02-17 07:04:55

标签: java compiler-errors identifier

所以我的Java在线课程,我必须包含变量并提供set和get方法来获取课程教师的名字,并显示消息:欢迎阅读成绩簿:本课程由以下人员提供:

班级成绩簿:

public class GradeBook
{
    private String courseName;
    public String courseTeacher;

    public GradeBook( String name, String teacher )
    {
        courseName = name;
        courseTeacher = teacher;
    }

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

    public String getCourseName()
    {
        return courseName;
    }

    public void setCourseTeacher( String teacher )
    {
        courseTeacher = teacher;
    }

    public String getcourseTeacher()
    {
        return courseTeacher;
    }

    public void displayMessage()
    {
        System.out.printf( " Welcome to the grade book for:/n%s!\n" ,         getCourseName() , "This course is presented by: \n%s\n!" ,getCourseTeacher() );
    }

}

主要课程:

import java.util.Scanner;

public class GradeBookTest
{
    public static void main( String[] args)
    {
        Scanner input = new Scanner( System.in );
        GradeBook myGradeBook = new GradeBook( "Cs101","Ciro" );

        System.out.println( "Please enter the course name:" );
        String theName = input.nextLine();
        myGradeBook.setCourseName( theName );

        System.out.println( "Please enter instructor name:" );
        String theTeacher = input.nextLine();
        myGradeBook.setCourseTeacher( theTeacher );

        System.out.println();
        myGradeBook.displayMessage();
    }
}

错误:

cannot find symbol method getCourseTeacher()      GradeBook      line 38

2 个答案:

答案 0 :(得分:4)

Java区分大小写,因此方法定义中getcourseTeacher应为getCourseTeacher(带有大写C):

public String getcourseTeacher()
                 ^ THIS

答案 1 :(得分:0)

首先,您需要指出哪条线是第38行给出错误。其次检查你的SETTER和GETTER。在GradeBook构造函数中,您将其指定为courseTeacher,因此您的setter和getter应该是“setCourseTeacher”和“getCourseTeacher”。