Source of GradeBook.java


  1: // Fig. 3.10: GradeBook.java
  2: // GradeBook class with a constructor to initialize the course name.
  3: 
  4: public class GradeBook
  5: {
  6:    private String courseName; // course name for this GradeBook
  7: 
  8:    // constructor initializes courseName with String supplied as argument
  9:    public GradeBook( String name )
 10:    {
 11:       courseName = name; // initializes courseName
 12:    } // end constructor
 13: 
 14:    // method to set the course name
 15:    public void setCourseName( String name )
 16:    {
 17:       courseName = name; // store the course name
 18:    } // end method setCourseName
 19: 
 20:    // method to retrieve the course name
 21:    public String getCourseName()
 22:    {
 23:       return courseName;
 24:    } // end method getCourseName
 25: 
 26:    // display a welcome message to the GradeBook user
 27:    public void displayMessage()
 28:    {
 29:       // this statement calls getCourseName to get the 
 30:       // name of the course this GradeBook represents
 31:       System.out.printf( "Welcome to the grade book for\n%s!\n", 
 32:          getCourseName() );
 33:    } // end method displayMessage
 34: 
 35: } // end class GradeBook
 36: 
 37: 
 38: /**************************************************************************
 39:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 40:  * Pearson Education, Inc. All Rights Reserved.                           *
 41:  *                                                                        *
 42:  * DISCLAIMER: The authors and publisher of this book have used their     *
 43:  * best efforts in preparing the book. These efforts include the          *
 44:  * development, research, and testing of the theories and programs        *
 45:  * to determine their effectiveness. The authors and publisher make       *
 46:  * no warranty of any kind, expressed or implied, with regard to these    *
 47:  * programs or to the documentation contained in these books. The authors *
 48:  * and publisher shall not be liable in any event for incidental or       *
 49:  * consequential damages in connection with, or arising out of, the       *
 50:  * furnishing, performance, or use of these programs.                     *
 51:  *************************************************************************/