如何解决?错误:符号找不到

时间:2013-11-22 03:44:21

标签: java algorithm

我无法编译文件,它在第12行和第13行出错。出现以下错误名称:

  

GradeBook.java:12:error:找不到符号courseName = name;   (此行显示一个箭头,指向“名称”的“n”。)符号:   变量名称位置:class GradeBook

     

GradeBook.java:13:error:找不到符号instructorName =   老师; (此行显示为指向“p”的箭头   “老师”)符号:变量教授位置:班级成绩簿

public class GradeBook
{
private String courseName; // nome do curso para esse GradeBook
private String instructorName; // nome do professor para esse GradeBook


public GradeBook (String courseName, String instructorName)
{
    courseName = name; 
    instructorName = professor;
} 


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


public String getCourseName()
{
    return courseName;
} 


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


public String getInstructorName()
{
    return instructorName;
} 


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

2 个答案:

答案 0 :(得分:1)

在它的构造函数中看到它引用了两个不存在'name'和'teacher'的变量。

public GradeBook (String courseName, String instructorName)
{
    courseName = name; // variable "name" is not declared anywhere
    instructorName = professor; // variable "teacher" was not declared.
} // fim do constructor

要修改此更改courseName,名称和老师为instructorName,它们是构造函数的参数。

看起来像这样:

public GradeBook (String courseName, String instructorName)
{
    this.courseName = courseName;
    this.instructorName = instructorName;
} // fim do construtor

答案 1 :(得分:0)

您将构造函数参数名称更改为name和professor而不是name和instructorname