Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 3. HR Matters a) Design and implement in a file p3.py a class hierarchy

ID: 3910671 • Letter: P

Question

Problem 3. HR Matters a) Design and implement in a file p3.py a class hierarchy for employees in a startup company. The base subclasses Manager, Engineer. Class Manager has a subclass Each employee has these: Data attributes: name (string), base salary (float), phone number (string). Make these private attributes _prefix). Constructor taking and saving as attributes name, phone number, and base salary. (Ensure proper call chain for superclass constructors.) .Methods: accessors for the name and the phone number and a method called salary_total0 that returns the total salary, including any extra benefits that subclasses might have. A method (called a mtator) that updates the base salary.

Explanation / Answer

#Employee class definition

class Employee:

          #private data attribute

          __name = ''

          __baseSalary = 0

          __phoneNo = ''

          #constructor function

          def __init__(self,nm,phone,bsal):

                self.__name = nm

                self.__baseSalary = bsal

                self.__phoneNo = phone

          #accessors methods

          def getName(self):

                 return self.__name

          def getphoneNo(self):

                 return self.__phoneNo

               

          #mutator method

          def setSalary(self, sal):

                 self.__baseSalary = sal

                

          #calculate salary

          def salary_total(self):

                 return self.__baseSalary

    

          def __repr__(self):

                 return 'Employee("%s","%s",%s)' % (self.getName(),self.getphoneNo(),self.salary_total())

          def __str__(self):

                 return 'Employee("%s","%s",%s)' % (self.getName(),self.getphoneNo(),self.salary_total())

# Engineer class definition            

class Engineer(Employee):

           #constructor function

           def __init__(self,nm,phone,bsal):

             super().__init__(nm,phone,bsal)   #calling Employee class constructor

              

           def salary_total(self):

                  return super().salary_total()

           def __repr__(self):

                 return 'Engineer("%s","%s",%s)' % (super().getName(),super().getphoneNo(),self.salary_total())

           def __str__(self):

                 return 'Engineer("%s","%s",%s)' % (super().getName(),super().getphoneNo(),self.salary_total())

#Manager class definition    

class Manager(Employee):

          __bonus = 0.0

          #constructor function

          def __init__(self,nm,phone,bsal,b):

                self.__bonus = b

                super().__init__(nm,phone,bsal)   #calling Employee class constructor

          def salary_total(self):

                  return super().salary_total() + self.__bonus

          def __repr__(self):

                 return 'Manager("%s","%s",%s)' % (super().getName(),super().getphoneNo(),self.salary_total())

          def __str__(self):

                 return 'Manager("%s", "%s", %s)' % (super().getName(),super().getphoneNo(),self.salary_total())

#CEO class definition    

class CEO(Manager):

          __stock = 0.0

          

          def __init__(self,nm,phone,bsal,b,stk):

                 self.__stock = stk

                 super().__init__(nm,phone,bsal,b) #calling Manager class constructor

          def salary_total(self):

                  return super().salary_total() + self.__stock

          def __repr__(self):

                 return 'CEO("%s","%s",%s)' % (super().getName(),super().getphoneNo(),self.salary_total())

          def __str__(self):

                 return 'CEO("%s", "%s", %s)' % (super().getName(),super().getphoneNo(),self.salary_total())

#function to print objects per line stored in list

def printf_staff(emplist):

      i = 0

      while i < 4:

          print(emplist[i])

          i = i + 1

def main():

       emplist = list()   #Creating list

       #creating objects of different class

       objEmp = Employee("Robert","121-2488888",75000)

       objEngineer = Engineer("John","421-2755555",150000)

       objManager = Manager("Sophia Loren","561-2977777",100000,25000.50)

       objCEO = CEO("Martin","563-3799999",80000,30000.80,75000.75)

       #Storing objects in list

       emplist.append(objEmp)

       emplist.append(objEngineer)

       emplist.append(objManager)

       emplist.append(objCEO)

       printf_staff(emplist) #calling printf_staff() function

main()   # calling main() function

      

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote