Question
Intro to Python Programming Create a superclass named Employee. The constructor must accept an id, name, and hourly pay rate. Provide getters for the three
Intro to Python Programming
Create a superclass named Employee. The constructor must accept an id, name, and hourly pay rate. Provide getters for the three data attributes along with a "pay" method that requires no additional parameters other than self. The "pay" method will return the salary due based on the pay rate * 40 (paid weekly). The str method will display the id and name of the employee.
Create a subclass of Employee named SalariedEmployee that has three constructor arguments (id, name, salary). Initialize the super class with id, name, and 0 (since salaried employees don't have an hourly rate). Initialize the self.salary instance variable with salary. Provide both a getter and setter for the salary. Override pay in the superclass to return the salary, paid monthly, divided by 12.
Create a test program that creates two Employees with different hourly pay rates and two SalariedEmployees with different annual salaries. Place these four objects in a list.
Find the highest and lowest pay. Sort on name and display the four employees.
Place each of the four in a dictionary that uses the id as the key. Iterate through the dictionary and display the pay of each.
Here is my code so far:
class Employee:
def __init__(self, id, name, rate): self.id = id self.name = name self.rate = rate def getId(self): return self.id def getName(self): return self.name def getRate(self): return self.rate def pay(self): return self.rate * 40 def __str__(self): return str(self.id) + " " + self.name class SalariedEmployee(Employee): def __init__(self, id, name, salary): Employee.__init__(self, id, name, 0) self.salary = salary def getSalary(self): return salary def setSalary(self, newSalary): self.salary = newSalary def pay(self): return self.salary / 12.0 def main(): e123 = Employee(123, "Joe", 10) e234 = Employee(234, "Sally", 20) e345 = SalariedEmployee(345, "Bob", 100000) print(e123) print(e345) main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started