please help me =( .. Modify class Gradebookas follows: a) Include a second Strin
ID: 3612814 • Letter: P
Question
please help me =( ..Modify class Gradebookas follows:
a) Include a second String instance variable that represents thename of the course's instructor name.
b) Provide a set method to change the instructor's name and a getmethod to retrieve it.
c) Modify the constructor to specify two parameters -- one for thecourse name and one for the instructor's name.
d) Modify method displayMessage such that it first outputs thewelcome message and course name, then outputs "This course ispresented by: " followed by the instructor's name.
Use your modified class in a test application that demonstrates theclass's new capabilities. please help me =( ..
Modify class Gradebookas follows:
a) Include a second String instance variable that represents thename of the course's instructor name.
b) Provide a set method to change the instructor's name and a getmethod to retrieve it.
c) Modify the constructor to specify two parameters -- one for thecourse name and one for the instructor's name.
d) Modify method displayMessage such that it first outputs thewelcome message and course name, then outputs "This course ispresented by: " followed by the instructor's name.
Use your modified class in a test application that demonstrates theclass's new capabilities.
Explanation / Answer
I will assume set/get methods according toconvention. public class Gradebook { // (a) new String instancevariable private Stringinstructor; // (b) set/get methods public voidsetInstructor(String name) { instructor=name; } public StringgetInstructor() { returninstructor; } // (c)constructor public Gradebook(Stringcourse, String instructor) { setInstructor(instructor); // if setCourse() does not exist, use the modifier thatcorresponds to the course instancevariable setCourse(course); } // (d) displayMessage() public StringdisplayMessage() { // you did not specify welcomeMessage. Includeit here in the String welcomeMessage. StringwelcomeMessage=""; returnwelcomeMessage+getcourse()+" This course is presented by:"+getInstructor(); } } For testing: public static void main(String[]args) { // create a new Gradebook Gradebook test=newGradeBook("Computer Science", "Dr. ________"); // test its new methods out.println(test.getInstructor()); test.setInstructor("Dr.________2"); out.println(test.getInstructor()); out.println(test.displayMessage()); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.