#类继承练习:人力系统
员工分为两类:全职员工 FullTimeEmployee、兼职员工 PartTimeEmployee。#全职和兼职都有"姓名 name"、"工号 id"属性,#-
井都具备"打印信息 print_info"(打印姓名、工号)方法。
梓全职有"月薪 monthly_salary"属性,
举兼职有"日薪 daily_salary"属性、"每月工作天数 work_days"的属性。#全职和兼职都有"计算月薪 calculate_monthly_pay"的方法,但具体计算过程不一样。
class Employee:
def __init__(self, name, emp_id):
self.name = name
self.emp_id = emp_id
def print_info(self):
print(f"Name: {self.name}")
print(f"ID: {self.emp_id}")
def calculate_monthly_pay(self):
pass
class FullTimeEmployee(Employee):
def __init__(self, name, emp_id, monthly_salary):
super().__init__(name, emp_id)
self.monthly_salary = monthly_salary
def calculate_monthly_pay(self):
return self.monthly_salary
class PartTimeEmployee(Employee):
def __init__(self, name, emp_id, daily_salary, work_days):
super().__init__(name, emp_id)
self.daily_salary = daily_salary
self.work_days = work_days
def calculate_monthly_pay(self):
return self.daily_salary * self.work_days
full_time_employee = FullTimeEmployee('Jiang', 'FT001', 5000)
part_time_employee = PartTimeEmployee('Qwq', 'PT001', 200, 20)
full_time_employee.print_info()
print(f"Monthly Pay: {full_time_employee.calculate_monthly_pay()}")
part_time_employee.print_info()
print(f"Monthly Pay: {part_time_employee.calculate_monthly_pay()}")