我正在使用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

最佳答案

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

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

public class GradeBookTest {

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

}


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

关于java - 我一直收到错误消息“找不到或加载主类gradebooktest.GradeBookTest”,我不确定为什么,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28689227/

10-11 22:26