我有以下代码:我可以添加到继承函数吗?
import locale
locale.setlocale(locale.LC_ALL, '') #Sets the locale to 'English_Canada.1252'
class Employee():
#Initlizes all of the info I need from the user
def __init__(self, lastName, firstName, payRate):
self.nameL = lastName
self.nameF = firstName
self.payRate = payRate #This payRate is an hourly pay rate
#Prints out the first and last name of the Employee in the form Employee(FirstName LastName)
def __repr__(self):
return('Employee(' + self.nameF + ' ' + self.nameL + ')')
#Changes the '+' key to add the hourlyPayRate of 2 Employee class types together
def __add__(self, otherSelf):
sumOfPay = self.payRate + otherSelf.payRate
return(sumOfPay)
def printCheque(self, numberOfHoursWorked):
if (numberOfHoursWorked > 40):
grossIncome = (numberOfHoursWorked - 40) * (self.payRate * 2)
grossIncome = grossIncome + (40 * self.payRate)
else:
grossIncome = numberOfHoursWorked * self.payRate
if(grossIncome > 42000):
taxPaid = grossIncome * 0.22
else:
taxPaid = grossIncome * 0.15
moneyMade = grossIncome - taxPaid
print('-'*80 + '\n')
print('PAY TO: '+ self.nameF + ' ' + self.nameL + ' '*38 + 'AMOUNT: ' + locale.currency(moneyMade)+'\n')
print('\n')
print('Gross Pay: '+locale.currency(grossIncome) + '\n')
print('Deductions: \n')
print(' Tax ',locale.currency(taxPaid), '\n')
return('-'*78)
class SalariedEmployee(Employee):
''
#payRate inherited from Employee will refer to salary here.
我必须做出类似的员工,但与这个人越过所支付的小时工资另一个类。我需要做的第一件事是将payRate更改为薪水。我不确定这会是什么样子,我尝试了一些东西,但他们没有奏效。
我需要做的另一件事是改变printCheque包括另一个税收,并且还显示休假时间。我是否可以在没有定义新功能的情况下将这样的功能添加到功能中,还是需要创建一个全新的功能?
不确定如何做到这两者中的任何一个,并且您可以给予的任何帮助都会有很大的帮助。
谢谢!
如何从第三个类继承out。是否仅仅从员工继承?或者我将不得不创建第三课。 – Dragonchicken 2014-11-25 04:14:09