Question: Software applications often use classes and objects to encapsulate logic about the real world. For example, a company might have software to track information about
Software applications often use classes and objects to encapsulate logic about the real world. For example, a company might have software to track information about employees. Let's use your knowledge of Python to create a simple example of such a system. Create a program called 'employee.py that defines an 'Employee' class with the following default properties: e name Assign each person an employee id that is one integer higher than the last assigned value. Also compute a 'reverse name' property that shows last name first. Your program should also define two sub-classes that inherit from Employee and define their own specific attributes and methods: e Manager o workers a list of workers who report to this manager o repr returns the person's name and a list of workers Worker o manager the manager to whom this worker reports o repr -returns the person's reverse name, and the name of their manager Note your Worker class will need to update the manager's list of workers when setting the worker's manager value. You can test your program like this: from employee import managerl - ManagerC "Warren Buffett) >>workeri Worker("John Doe, manager1) > workerl Name: Doe, John, id: 2, reports to: Warren Buffett worker WorkerC"Jane Doe" >>worker Name: Doe, Jane, id: 3, reports to: -NA worker3 Worker("Joe Schmoe, manager1) >>manager Name: Warren Buffet investor, id: 1 Workers: 2 Doe, John
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
