gpt4 book ai didi

java - 我不断收到错误消息 "Could not find or load main class gradebooktest.GradeBookTest"我不知道为什么

转载 作者:行者123 更新时间:2023-12-01 11:52:31 24 4
gpt4 key购买 nike

我使用的是netbeans,我的代码如下

public class GradeBook
{
private String courseName; // course name for this GradeBook
private String courseInstructor; // instructor name for this GradeBook

// constructor initializes courseName and courseInstructor with String Argument
public GradeBook( String name, String insname ) // constructor name is class name
{
courseName = name; // initializes courseName
courseInstructor = insname; // initializes courseInstructor
} // end constructor

// method to set the course name
public void setCourseName( String name )
{
courseName = name; // store the course name
} // end method setCourse

// method to retrieve the course name
public String getCourseName()
{
return courseName;
} // end method getCourseName

// method to set the Instructor name
public void setInstructorName( String insname)
{
courseInstructor = insname; // store the Instructor name
} // end method setInstructorName

// method to retrieve the Instructor name
public String getInstructorName()
{
return courseInstructor;
} // end method getInstructorName

// display a welcome message to the GradeBook user
public void displayMessage()
{
// this statement calls getCourseName to get the
// name of the course this GradeBook represents
System.out.println( "\nWelcome to the grade book for: \n"+
getCourseName()+"\nThis course is presented by: "+getInstructorName());
System.out.println( "\nProgrammed by Jack Friedman");

} // end method displayMessage
} // end

最佳答案

您应该在主方法中调用此类的构造函数。

创建一个新类 GradeBookTest,如下所示:

public class GradeBookTest {

public static void main (String args[]) {
GradeBook book = new GradeBook("Math", "T.I.");
book.displayMessage(); //To see your results
}

}

现在您可以启动此类来查看结果。

关于java - 我不断收到错误消息 "Could not find or load main class gradebooktest.GradeBookTest"我不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28689227/

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