gpt4 book ai didi

java - 可以找到错误

转载 作者:行者123 更新时间:2023-12-01 18:36:23 24 4
gpt4 key购买 nike

因此,在我的 Java 在线类(class)中,我必须包含变量并提供 set 和 get 方法来获取类(class)讲师的姓名,并显示消息:欢迎来到以下类(class)的成绩册: 本类(class)由以下人员介绍:

类(class)成绩簿:

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

最佳答案

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

public String getcourseTeacher()
^ THIS

关于java - 可以找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21822750/

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