gpt4 book ai didi

java - 怎么解决?错误 : symbol cannot find

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:07:39 26 4
gpt4 key购买 nike

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

GradeBook.java: 12: error: can not find symbol courseName = name; (this line appears an arrow pointing to the "n" of "name.") Symbol: variable name location: class GradeBook

GradeBook.java: 13: error: can not find symbol instructorName = teacher; (this line appears an arrow pointing to the "p" for "teacher") symbol: variable Professor location: class GradeBook

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

最佳答案

在它的构造函数中看到它,您正在引用两个不存在的变量“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 by name 和 teacher for instructorName 这是构造函数的参数。

看起来像这样:

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

关于java - 怎么解决?错误 : symbol cannot find,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20136639/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com