Problem 1. Modifying Class GradeBook (Fig. 5.1). Include a second String instanc
ID: 3725550 • Letter: P
Question
Problem 1. Modifying Class GradeBook (Fig. 5.1). Include a second String instance variable that represents the name of the course's instructor. Provide a set method to change the instructor's name and a get method to retrieve it. Modify the constructor to specify two parameters-one for the course name and one for the instructor's 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 instructor's name. Modify the test application (Fig. 5.2) to demonstrate the class's new capabilities Sample OutputExplanation / Answer
Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
GradeBook.java
================
public class GradeBook{
private String courseName;
private String instructorName;
public GradeBook(String name, String instructor){
courseName = name;
instructorName = instructor;
}
public void setCourseName(String name){
courseName = name;
}
public String getCourseName(){
return courseName;
}
public void setInstructorName(String name){
instructorName = name;
}
public String getInstructorName(){
return instructorName;
}
public void displayMessage(){
System.out.printf("Welcome to the grade book for %s! ", getCourseName());
System.out.printf("This course is presented by: %s ", getInstructorName());
}
}
GradeBookTest.java
================
public class GradeBookTest {
public static void main(String[] args) {
GradeBook gradeBook1 = new GradeBook("CS101 Introduction to Java Programming", "Sam Smith");
gradeBook1.displayMessage();
System.out.printf(" Changing instructor name to Judy Jones ");
gradeBook1.setInstructorName("Judy Jones");
gradeBook1.displayMessage();
}
}
------output-----
Welcome to the grade book for
CS101 Introduction to Java Programming!
This course is presented by: Sam Smith
Changing instructor name to Judy Jones
Welcome to the grade book for
CS101 Introduction to Java Programming!
This course is presented by: Judy Jones
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.