我需要使用python类将奖金值添加到employee对象中

2024-06-25 07:26:35 发布

您现在位置:Python中文网/ 问答频道 /正文

from Employee_Maker import Employee


def fileread():
    f = open("Dirany.txt",'r')
    txt = f.readlines()
    for lines in txt:
        print(lines)
    return txt

def EmpObj(txt):
    company = Queue.Queue()
    for employee in txt:
        empList = employee.split('\t')
        first = empList[0]
        last = empList[1]
        pay = empList[2]
        employee = Employee(first, last, int(pay))
        company.enqueue(employee)
    return company

def bonuscalc(txt):
    txt.getPay
    total_bonus = 0
    bonus_rate = .20
    for pay in txt:
       bonus = pay * bonus_rate
       bonus_rate -= .01
       total_bonus += bonus
       
def main():
    txt = fileread()
    txt2 = EmpObj(txt)
    txt2.print_queue()
main()
class Employee:
    def __init__(self,first,last,pay):
        self.first=first
        self.last=last
        self.pay=pay
        self.bonus=0
        self.email=first+'.'+last+'@company.com'

    def getPay(self):
        return self.pay

    def setPay(self,pay):
        self.pay=pay
        
    def fullName(self):
        return '{} {}'.format(self.first, self.last)
       
    def getBonus(self):
        return self.bonus

    def setBonus(self,bonus):
        self.bonus=bonus

    def __str__(self):
       return 'Employee name: '+self.fullName()+' Employee pay: ' +str(self.pay) + ' Employee bonus ' + str(self.bonus)

正如你所看到的,我只是不知道如何将奖金计算到employee对象中,我已经设置了数学和for循环,但现在它一直显示为零,可能与我导入的类有关,我不太确定


Tags: inselftxtforreturnratedefemployee