Modify class GradeBook. Include a second string instance variable that represents the name of the course's instructor. provide a set method and a get method to retrieve it. modify the constructor to speciy two perameters - one for the course and one for the instructors name. modify method displaymessage such that it first outputs the welcome message and course name, then outputs "this course is presented by: "followed by the instructors name. modify the test application to demonstrate the class's new capabilities.
SAMPLE OUTPUT:
Welcome to the gradebook for
CS101 Introduction to Java Programming!
This course is presented by: Sam Smith
Changing instructor name to Judy Jones
Welcome to the gradebook for
CS101 Introduction to Java Programming!
This course is presented by: Judy Jones
HERE IS THE FIRST PAGE
public class GradeBook
{
private String courseName; // course name for this GradeBook
/* WRITE CODE TO DECLARE A SECOND STRING INSTANCE VARIABLE*/
// constructor initializes courseName with String supplied as argument
public GradeBook( String name )
{
courseName = name; // initializes courseName
} // end constructor
// method to set the course name
public void setCourseName( String name )
{
courseName = name; // store the course name
} // end method setCourseName
// method to retrieve the course name
public String getCourseName()
{
return courseName;
} // end method getCourseName
/*WRITE CODE TO DECLARE A GET AND A SET METHOD FOR THE INSTRUCTOR'S NAME*/
// 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.printf( "Welcome to the grade book for\n%s!\n",
getCourseName() );
/*WRITE CODE TO OUTPUT THE INSTRUCTOR'S NAME*/
} // end method displayMessage
} // end class GradeBook
HERE IS THE SECOND PAGE
public class GradeBookTest
{
// main method begins program execution
public static void main( String args[] )
{
// create GradeBook object
GradeBook gradeBook1 = new GradeBook(
"CS101 Introduction to Java Programming" );
// display initial value of courseName for each GradeBook
System.out.printf( "gradeBook1 course name is: %s\n",
gradeBook1.getCourseName() );
/*WRITE CODE TO CHANGE INSTRUCTOR'S NAME AND OUTPUT CHANGES */
} // end main
} // end class GradeBookTest
This post has been edited by AZZHHOLES: 09 July 2005 - 03:33 PM