[Solved] Exercise Refactoring Working Program Code Refactoring Process Improve Existing Code Term I Q37200368
In this exercise, we will be refactoring a working program. Coderefactoring is a process to improve an existing code in term of itsinternal structure without changing its external behavior.
In this particular example, we have three classes Course,Student, Instructor in addition to Main. All classes are welldocumented. Read through them to understand their structure. Inbrief, Course models a course that has a title, max capacity aninstructor and students. Instructor models a course instructor whohas a name, id and salary. Student models a student who has a name,id, and credits. The Main class create hypothetical instructor,students and course and calls the method print in each object toformat the output (see below).
Hani Javadi, instructor ID: 888777666, salary: 11111.0— — —Joe Loop, student ID: 810123456, credits: 10— — —Mary Collection, student ID: 811987321, credits: 25— — —Ke Method, student ID: 810010101, credits: 0— — —MIST 4700 MWF 6am-7amInstructor: Hani Javadi Room: Z101Class list:Joe Loop, student ID: 810123456, credits: 10Mary Collection, student ID: 811987321, credits: 25Ke Method, student ID: 810010101, credits: 0Number of students: 3
This program is working and fully functional. However, there isa substantial code duplication between Student and Instructor. Yourjob is to eliminate this redundancy and improve the programstructure by following these steps:
- Make both Student and Instructor subclasses of Person
- Move the common attributes (name & id) from Instructor& Student to Person
- Move the common methods getName, setName, getID, setID,getLoginName to Person
- Create a method print() in Person, in this method print thename of the person: System.out.print(name);
- Modify the methods print() in Student and Instructor by makingthem
- Call super.print()
- Then printing the IDs, credits and salary respectively
Effectively the super class Person will take care of printingname, then the subclasses will provide the added functionality ofdisplaying ID and credits (Student) and salary (Instructor)
The Main and Course classes should compile and work as usual atthis point producing exactly same output as above. Happyrefactoring!
Expert Answer
Answer to In this exercise, we will be refactoring a working program. Code refactoring is a process to improve an existing code in… . . .
OR

