定义员工类,具有底薪、出勤天数、销售额属性和获得月薪的方法。定义销售员工类,计算本 月的总薪资。销售员工月薪:底薪 + 全勤绩效 + 销售额 + 提成。底薪为固定数额,出勤天数23天即为全勤,绩效为500元,缺勤一天无奖金。员工提成按销售额分档计算,1000元以内提成5%,1000元至2000元之间提成10%,2000-4000元提成15%,4000元以上提成20%)
时间: 2023-12-22 10:04:29 浏览: 185
以下是员工类和销售员工类的定义:
```python
class Employee:
def __init__(self, base_salary, attendance_days, sales):
self.base_salary = base_salary
self.attendance_days = attendance_days
self.sales = sales
def get_monthly_salary(self):
full_attendance_bonus = 0
if self.attendance_days == 23:
full_attendance_bonus = 500
commission_rate = 0
if self.sales < 1000:
commission_rate = 0.05
elif self.sales < 2000:
commission_rate = 0.1
elif self.sales < 4000:
commission_rate = 0.15
else:
commission_rate = 0.2
commission = self.sales * commission_rate
monthly_salary = self.base_salary + full_attendance_bonus + self.sales + commission
return monthly_salary
class SalesEmployee(Employee):
def __init__(self, base_salary, attendance_days, sales):
super().__init__(base_salary, attendance_days, sales)
def get_monthly_salary(self):
full_attendance_bonus = 0
if self.attendance_days == 23:
full_attendance_bonus = 500
commission_rate = 0
if self.sales < 1000:
commission_rate = 0.05
elif self.sales < 2000:
commission_rate = 0.1
elif self.sales < 4000:
commission_rate = 0.15
else:
commission_rate = 0.2
commission = self.sales * commission_rate
monthly_salary = self.base_salary + full_attendance_bonus + self.sales + commission
return monthly_salary
```
其中,`Employee` 类具有底薪、出勤天数和销售额属性,以及计算月薪的方法 `get_monthly_salary()`。`SalesEmployee` 类继承自 `Employee` 类,同时覆写了 `get_monthly_salary()` 方法,计算销售员工的月薪。在计算月薪时,需要考虑全勤绩效和提成。全勤绩效为固定值,提成根据销售额分档计算。
阅读全文