Python programming problem: Write a class named Employee that holds the followin
ID: 3574811 • Letter: P
Question
Python programming problem:
Write a class named Employee that holds the following data: name, salary, and years of service. Create private instance variables to store these data. Do the following in the Employee class:
Write an __init__ method that accepts the employee’s name, salary and years of service as arguments. Write statements in __init__ to store them in the instance variables.
Write three getter methods to retrieve the instance variables.
Write a method to calculate the monthly pension payout the employee will receive in retirement: monthly pension payout = salary * years of service * 0.0015
The main function of this program is partially written. Variables are created for name, salary and years of service. Do the following:
Use the data provided to create an Employee object.
Write statements to display the three instance variables of the Employee objects
Write statements to calculate and display the monthly pension payout of this employee.
The following is the expected output of the program:
Name: Joe Chen
Salary: 80000
Years of service: 30
Monthly pension payout: 3600.0
Process finished with exit code 0
Explanation / Answer
*********************************Program**************************************
#!/usr/bin/python
class Employee:
def __init__(self, name, salary,yos):
self.name = name
self.salary = salary
self.yos = yos
def displayEmployee(self):
print "Name : ", self.name,
def displaySal(self):
print " Salary : ",self.salary
def displayYos(self):
print "Years of Service : ",self.yos
def pensionPayout(self):
print "Monthly Pension Payout:",self.salary * self.yos * 0.0015
"This would create first object of Employee class"
emp1 = Employee("Jon Chen", 80000,30)
emp1.displayEmployee()
emp1.displaySal()
emp1.displayYos()
emp1.pensionPayout()
****************************output***********************************
python main.py
Name : Jon Chen
Salary : 80000
Years of Service : 30
Monthly Pension Payout: 3600.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.