Design and implement a set of classes that define the


Lab Assignment

Task 1-Inheritance Design

Design and implement a set of classes that define the employees of a hospital: doctor, nurse, and surgeon.

1. The parent class HopitalEmployee contains two protected instance variables: String name and int number. Set up the constructor. Implement the getter and setter methods for each instance variable. Add the toString method.

2. Add the following method to the parent class:

public void work()
{
System.out.println (name + " works for the hospital.");
}

3. Implement two subclasses: Nurse, and Doctor. Besides the inherited variables, Doctor has a new instance variable for specialty, Nurse has a new variable numOfPatients. Implement constructor and override the toString method for these two classes.

4. Now we need to create another class represent surgeon. Consider where you should put this class in the hierarchy. Besides the inherited variables, this class should have a new instance variable operating, which indicates the surgeon is on operating or not. Complete the constructor and toString method for Surgeon class.

5. Now run the tester program Hospital.java provided. Make sure everything is all right before move on.

The expected output is:
Vito 123
Michael 234 Heart
Vincent 645 Brain Operating: true
Sonny 789 has 6 patients.
Vito works for the hospital.
Michael works for the hospital.
Vincent works for the hospital.
Sonny works for the hospital.

6. Override the work() method in each of the three subclasses. Besides printing out that this person works for the hospital, add some more information of this person. Reference the expected output below:

The expected output is:
Vito 123
Michael 234 Heart
Vincent 645 Brain Operating: true
Sonny 789 has 6 patients.
Vito works for the hospital.
Michael works for the hospital. Michael is a(n) Heart doctor.
Vincent works for the hospital. Vincent is operating now.
Sonny works for the hospital. Sonny is a nurse with 6 patients.

Attachment:- Hospital.rar

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Design and implement a set of classes that define the
Reference No:- TGS02651350

Expected delivery within 24 Hours