In: Computer Science
Consider the relationship, "Doctor is-an Employee" and "Nurse is-an Employee", in the context of a Hospital. Doctors and Nurses both have a name, gender, address, id, salary, and degree. Both salary and degree are private variables. Moreover, Doctors have their "clinical specialization" (ex: "cardiac", "radiology", etc.) and a consulting "room number", and Nurses have "work shifts" (ex: "morning", "evening", "night", etc.). You are required to write Python classes to represent doctors and nurses. Your class should have a function to increment the number of patients for a doctor, if the number of patients is more than 20, then print a message "Daily Limit Reached" and return -1, if the number is less than or equal to 20 the function should return the total number of patients that the doctor attended. Your program must also have a function to display the total number of employees in the hospital. Write the constructor and other required methods to complete your code. The program should have functions to display all necessary details. Test the class by creating two objects of the class Doctor and two objects of class Nurse, and test for more than 20 patients for the doctor.
# Defines super class Employee
class Employee:
countEmployee = 0
# Parameterized constructor to assign parameter values to data
member
def __init__(self, name, gender, address, ID, salary,
degree):
self.name = name
self.gender = gender
self.address = address
self.ID = ID
self.__salary = salary
self.__degree = degree
self.countEmployee += 1
# Setter function to set name
def setName(self, name):
self.name = name
# Setter function to set gender
def setGender(self, gender):
self.gender = gender
# Setter function to set address
def setAddress(self, address):
self.address = address
# Setter function to set ID
def setID(self, ID):
self.ID = ID
# Setter function to set salary
def setSalary(self, salary):
self.__salary = salary
# Setter function to set degree
def setDegree(self, degree):
self.__degree = degree
# Getter function to return name
def getName(self):
return self.name
# Getter function to return gender
def getGender(self):
return self.gender
# Getter function to return address
def getAddress(self):
return self.address
# Getter function to return ID
def getID(self):
return self.ID
# Getter function to return salary
def getSalary(self):
return self.__salary
# Getter function to return degree
def getDegree(self):
return self.__degree
# Defines a function to display employee information
def showEmployee(self):
print("\n Name: ", self.name, "\n Gender: ", self.gender,
"\n Address: ", self.address, "\n ID: ", self.ID,
"\n Salary: $", self.__salary,
"\n Degree: ", self.__degree, end = '')
# Defines sub class Doctor derived from supuer class
Employee
class Doctor(Employee):
# Parameterized constructor to assign parameter values to data
member
def __init__(self, name, gender, address, ID, salary, degree,
specialization, roomNumber):
# Calls the super class constructor
Employee.__init__(self, name, gender, address, ID, salary,
degree)
self.specialization = specialization
self.roomNumber = roomNumber
self.countPatient = 0
# Setter function to set specialization
def setSpecialization(self, specialization):
self.specialization = specialization
# Getter unction to return specialization
def getSpecialization(self):
return self.specialization
# Getter unction to return room number
def getRoomNumber(self):
return self.roomNumber
# Setter function to set room number
def setRoomNumber(self, roomNumber):
self.roomNumber = roomNumber
def addPatient(self):
if self.countPatient >= 20:
print(" Daily Limit Reached for Doctor: ", self.getName())
return -1
else:
self.countPatient += 1
return self.countPatient
# Defines a function to display doctor information
def showDoctor(self):
self.showEmployee()
print("\n Specialization: ", self.specialization,
"\n Consulting room number: ", self.roomNumber)
# Defines sub class Nurse derived from supuer class
Employee
class Nurse(Employee):
# Parameterized constructor to assign parameter values to data
member
def __init__(self, name, gender, address, ID, salary, degree,
workShifts):
# Calls the super class constructor
Employee.__init__(self, name, gender, address, ID, salary,
degree)
self.workShifts = workShifts
# Setter function to set work shifts
def setSpecialization(self, workShifts):
self.workShifts = workShifts
# Getter function to return workShifts
def getSpecialization(self):
return self.workShifts
# Defines a function to display nurse information
def showNurse(self):
self.showEmployee()
print("\n Work Shifts: ", self.workShifts)
# Creates objects for Doctor class
doctorOne = Doctor('Pyari', "male", "Berhampur", 1111, 200000,
"MBBS",
"Radiology", 102)
doctorTwo = Doctor('Manvi', "female", "Bangalore", 2222, 288000,
"MBBS",
"Cardiac", 207)
# Creates objects for Nurse class
nurseOne = Nurse('Ramesh', "male", "Bhubaneswar", 1234, 15000,
"NCR",
"Morning")
nurseTwo = Nurse('Rita', "female", "Rourkela", 3213, 22000,
"CCR",
"Evening")
# Loops 22 times to add patient to doctor one
for c in range(22):
doctorOne.addPatient()
# Loops 9 times to add patient to doctor two
for c in range(9):
doctorTwo.addPatient()
# Displays the doctors information
print("************** Doctors Information ************** ")
doctorOne.showDoctor()
print(" Total number of patients doctor ",
doctorOne.getName(),
" attended: ", doctorOne.countPatient)
doctorTwo.showDoctor()
print(" Total number of patients doctor ",
doctorTwo.getName(),
" attended: ", doctorTwo.countPatient)
print("************** Nurses Information ************** ")
# Displays nurses information
nurseOne.showNurse()
nurseTwo.showNurse()
print("\n Total number of employees: ",
(doctorOne.countEmployee + doctorOne.countEmployee +
nurseOne.countEmployee + nurseTwo.countEmployee))
Sample Output:
Daily Limit Reached for Doctor: Pyari
Daily Limit Reached for Doctor: Pyari
************** Doctors Information **************
Name: Pyari
Gender: male
Address: Berhampur
ID: 1111
Salary: $ 200000
Degree: MBBS
Specialization: Radiology
Consulting room number: 102
Total number of patients doctor Pyari attended: 20
Name: Manvi
Gender: female
Address: Bangalore
ID: 2222
Salary: $ 288000
Degree: MBBS
Specialization: Cardiac
Consulting room number: 207
Total number of patients doctor Manvi attended: 9
************** Nurses Information **************
Name: Ramesh
Gender: male
Address: Bhubaneswar
ID: 1234
Salary: $ 15000
Degree: NCR
Work Shifts: Morning
Name: Rita
Gender: female
Address: Rourkela
ID: 3213
Salary: $ 22000
Degree: CCR
Work Shifts: Evening
Total number of employees: 4