我需要写一个名为Employee的类,保存姓名、工资和从业年限的数据。它可以计算员工退休后每月领取的养老金,并显示Employee对象的三个实例变量。同时,它还调用Employee对象的pension方法来计算此员工的每月养老金支出,并将其显示出来。
但是,我在运行程序后没有得到任何输出,这就是具体的问题。
我应该得到像这样的输出:
这里是完整的代码。
Name: Joe Chen
Salary: 80000
Years of service: 30
Monthly pension payout: 3600.0
Process finished with exit code 0
这里是完整的代码。
class Employee:
# init method implementation
def __init__(self, EmpName, EmpSalary, EmpYos):
self.EmpName = EmpName
self.EmpSalary = EmpSalary
self.EmpYos = EmpYos
def displayEmployeeDetails(self):
print "\nName ", self.EmpName,
# defines the salary details
def displaySalary(self):
print "\nSalary", self.EmpSalary
# defines the years of service
def displayYoservice(self):
print "\nYears of Service", self.EmpYos
# defines pension
def MonthlypensionPayout(self):
print "\nMonthly Pension Payout:", self.EmpSalary * self.EmpYos * 0.0015
def main():
# creates instance for employee 1
Emplo1 = Employee("Joe Chen", 80000, 30)
# creates instance for employee 2
Emplo2 = Employee("Jean park", 60000, 25)
# Function calls
Emplo1.displayEmployeeDetails()
Emplo1.displaySalary()
Emplo1.displayYoservice()
Emplo1.MonthlypensionPayout()
# function calls
Emplo2.displayEmployeeDetails()
Emplo2.displaySalary()
Emplo2.displayYoservice()
Emplo2.MonthlypensionPayout()
main()