Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Last weeks lab. class EmployeeO: def __init__(self, empl_num, name,birth_month,birth year,job_title,salary): self.empl_numempl_num self.namename self.birth month-birth_month self.birth_year - birth year self.job_title -job_title seLf.salary-salary def str_(self): return (str(self.empl_num)
Last weeks lab.
class EmployeeO: def __init__(self, empl_num, name,birth_month,birth year,job_title,salary): self.empl_numempl_num self.namename self.birth month-birth_month self.birth_year - birth year self.job_title -job_title seLf.salary-salary def str_(self): return (str(self.empl_num) ", " + str(self.name) + ", Birth Date-"+ str(self.birth_month)"" str(self.birth year)", Job-"+ str(self.job title)", Salary-"str(self.salary) + ", Hourly Rate-$10:.2f/hr".format(self.hourly_rateO) + ", " def hourly_rate (self): if self.salary > 0: return int(self.salary)/2080 def age (self): if self.birth year 1800 and self.birth_month 2: elif self.birth_year 1800 and self.birth_month > 2: else: return (2019 - self.birth year) return (2019 - self.birth year- 1) return 0 def can_retire (self): years self.ageO if years>65: return True else: return False el Employee('E34568 ', 'David Mier', 3, 1996, 'Accountant', 65000) e2Employee'E22154', Margarete Smith', 10, 1972, 'Vice President', 115000) e3 - Employee( E43344, "Chase Smedley', 8, 1988, 'Salesman', 75000) e4EmployeeC'E12157', "Daniel Arledge', 11, 1952, 'Lawyer', 92000) print("Employee 1 ::") print(e1.__str__O) print("nAge is",e1.ageO) print(" Can Retire ::",el.can_retireO,"n") The enhancements you are to add in this week's lab include: 1. Protect all attributes from direct "dot notation" access from outside the class 2. Add accessor/mutator (getter/setter) methods to return or change the object's job..title and salary - return the value for accessor methods and 'True' for successful mutator methods 3. Add an equals method to determine whether an input object is the same as the 'self' object. Equality is assumed when 'emplnum' and 'name' match As with last week create several employee objects. Here's an example: el Employee(E34568', 'David Miller', 1960, 3, 'Accountant', 65000) e2 EmployeeCE22154', 'Margarete Smith', 1972, 10, Vice President, 115000) e3 Employee('E43344', 'Chase Smedley', 1982, 8, 'Salesman', 75000) e4 -Employee(E12157, 'Daniel Arledge', 1952, 11, Lawyer', 92000) Then print each object, the age of the employee, and their retirement eligibility. Retrieve and print each attribute value from at least one object to show that the accessor method works. Change each attribute for at least one object to show the mutator method works. Print the resulting new attribute value using the accessor method for that attribute Create an additional employee object that has some of the same information as an existing object to show the 'equals' method works. Print the result of the comparison. Execute the equals' method with two objects that are not the same to show rejection in when the objects do not have the same state. Print the result of the comparison. To create and test the Employee class do the following: The programs output will be minimal, but is expected to have the following lines Start of Enhanced Employee class definition program output as specified above> class EmployeeO: def __init__(self, empl_num, name,birth_month,birth year,job_title,salary): self.empl_numempl_num self.namename self.birth month-birth_month self.birth_year - birth year self.job_title -job_title seLf.salary-salary def str_(self): return (str(self.empl_num) ", " + str(self.name) + ", Birth Date-"+ str(self.birth_month)"" str(self.birth year)", Job-"+ str(self.job title)", Salary-"str(self.salary) + ", Hourly Rate-$10:.2f/hr".format(self.hourly_rateO) + ", " def hourly_rate (self): if self.salary > 0: return int(self.salary)/2080 def age (self): if self.birth year 1800 and self.birth_month 2: elif self.birth_year 1800 and self.birth_month > 2: else: return (2019 - self.birth year) return (2019 - self.birth year- 1) return 0 def can_retire (self): years self.ageO if years>65: return True else: return False el Employee('E34568 ', 'David Mier', 3, 1996, 'Accountant', 65000) e2Employee'E22154', Margarete Smith', 10, 1972, 'Vice President', 115000) e3 - Employee( E43344, "Chase Smedley', 8, 1988, 'Salesman', 75000) e4EmployeeC'E12157', "Daniel Arledge', 11, 1952, 'Lawyer', 92000) print("Employee 1 ::") print(e1.__str__O) print("nAge is",e1.ageO) print(" Can Retire ::",el.can_retireO,"n") The enhancements you are to add in this week's lab include: 1. Protect all attributes from direct "dot notation" access from outside the class 2. Add accessor/mutator (getter/setter) methods to return or change the object's job..title and salary - return the value for accessor methods and 'True' for successful mutator methods 3. Add an equals method to determine whether an input object is the same as the 'self' object. Equality is assumed when 'emplnum' and 'name' match As with last week create several employee objects. Here's an example: el Employee(E34568', 'David Miller', 1960, 3, 'Accountant', 65000) e2 EmployeeCE22154', 'Margarete Smith', 1972, 10, Vice President, 115000) e3 Employee('E43344', 'Chase Smedley', 1982, 8, 'Salesman', 75000) e4 -Employee(E12157, 'Daniel Arledge', 1952, 11, Lawyer', 92000) Then print each object, the age of the employee, and their retirement eligibility. Retrieve and print each attribute value from at least one object to show that the accessor method works. Change each attribute for at least one object to show the mutator method works. Print the resulting new attribute value using the accessor method for that attribute Create an additional employee object that has some of the same information as an existing object to show the 'equals' method works. Print the result of the comparison. Execute the equals' method with two objects that are not the same to show rejection in when the objects do not have the same state. Print the result of the comparison. To create and test the Employee class do the following: The programs output will be minimal, but is expected to have the following lines Start of Enhanced Employee class definition program output as specified above>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