Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help especially with the entire part (b) a) Design and implement in a file p3.py a class hierarchy for employees in a startup company.

image text in transcribed

Please help especially with the entire part (b)

a) Design and implement in a file p3.py a class hierarchy for employees in a startup company. The base class is Employee. This has subclasses Manager, Engineer. Class Manager has a subclass called CEO. 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 mutator) that updates the base salary. Thestr_method to generate a string representing the object. E.g. "Manager("Sophia method to generate the official string representation of the object. An Engineer object does not have anything in addition to what an Employee has. A Manager has in addition to Employee a bonus (float). Its total salary is the base salary +bonus A CEO has in addition (to a Manager) stock options (float). Its total salary is the base salary+bonus+ stock options. (in the real world stock options are never added to the salary, though) The salary_total method must be overridden in subclasses to compute the total salary as described above. It should NOT access the superclass base salary attribute, but it should use the salary_total0 method provided by the base class or superclass. b) Write a function print staffO that takes a sequence (e.g. a list) of employee objects (incl. subclass instances) and prints their name, phone#, and total salary, with one object per line. Write a mainO method in file p3.py that demonstrates the classes described above. Among other code, create in main0 several instances of each class in the employee hierarchy and add them to a list, then call print_staffO on that list. (if everything works correctly, this is an illustration of polymorphism) a) Design and implement in a file p3.py a class hierarchy for employees in a startup company. The base class is Employee. This has subclasses Manager, Engineer. Class Manager has a subclass called CEO. 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 mutator) that updates the base salary. Thestr_method to generate a string representing the object. E.g. "Manager("Sophia method to generate the official string representation of the object. An Engineer object does not have anything in addition to what an Employee has. A Manager has in addition to Employee a bonus (float). Its total salary is the base salary +bonus A CEO has in addition (to a Manager) stock options (float). Its total salary is the base salary+bonus+ stock options. (in the real world stock options are never added to the salary, though) The salary_total method must be overridden in subclasses to compute the total salary as described above. It should NOT access the superclass base salary attribute, but it should use the salary_total0 method provided by the base class or superclass. b) Write a function print staffO that takes a sequence (e.g. a list) of employee objects (incl. subclass instances) and prints their name, phone#, and total salary, with one object per line. Write a mainO method in file p3.py that demonstrates the classes described above. Among other code, create in main0 several instances of each class in the employee hierarchy and add them to a list, then call print_staffO on that list. (if everything works correctly, this is an illustration of polymorphism)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions