Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program 1 - GradeBook class modifications Modify class GradeBook ( Fig 3.10 ) as

ID: 3623201 • Letter: P

Question

Program 1 - GradeBook class modifications

Modify class GradeBook ( Fig 3.10 ) as follows:

1. Include a second String instance variable (field) that represents the name of the course's instructor.
2. Provide a set method to change the instructor's name and a get method to retrieve it.
3. Modify the constructor to specify two parameters - one for the course name and one for the instructor's name.
4. Modify method displayMessage such that it first outputs the welcome message and course name, then outputs "This course is presented by: " followed by the instructor's name.

Use your modified class in a test application that demonstrates the class's new capabilities.

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

// 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

// 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 %s! ",
getCourseName() );
} // end method displayMessage

} // end class GradeBook


GradeBookTest
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" );
GradeBook gradeBook2 = new GradeBook(
"CS102 Data Structures in Java" );

// display initial value of courseName for each GradeBook
System.out.printf( "gradeBook1 course name is: %s ",
gradeBook1.getCourseName() );
System.out.printf( "gradeBook2 course name is: %s ",
gradeBook2.getCourseName() );
} // end main

} // end class GradeBookTest

Explanation / Answer



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

// constructor initializes courseName with String supplied as argument
public GradeBook( String name, String instructor )
{
courseName = name; // initializes courseName
instructorName = instructor;
} // end constructor

// method to set the Instructor name
public void setInstructorName( String name )
{
instructorName = name; // store the course name
} // end method setCourseName

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


//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
// 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 %s! ",
getCourseName() );
System.out.printf( "This course is presented by: %s ",
getInstructorName() );
} // end method displayMessage


public static void main(String[] args) {
GradeBook bk = new GradeBook("CS101","Peter");

bk.displayMessage();
}
} // end class GradeBook

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote