2024/11/8

from abc import ABC, abstractmethod
from datetime import datetime


class People:
def __init__(self, name, gender, birthday):
self.name = name
self.gender = gender
self.age = birthday

def display(self):
print("姓名:", self.name)
print("性别:", self.gender)
print("年龄:", self.age)

class Teacher(People):
def __init__(self, name, gender, birthday, position, teaching_hours):
super().__init__(name, gender, birthday)
self.position = position
self.teaching_hours = teaching_hours

@abstractmethod
def calculate_salary(self):
pass

class Professor(Teacher):
def __init__(self, name, gender, birthday, teaching_hours):
super().__init__(name, gender, birthday, "教授", teaching_hours)

def calculate_salary(self):
fixed_salary = 5000
hourly_allowance = 50
total_salary = fixed_salary + self.teaching_hours * hourly_allowance
return total_salary

class AssociateProfessor(Teacher):
def __init__(self, name, gender, birthday, teaching_hours):
super().__init__(name, gender, birthday, "副教授", teaching_hours)

def calculate_salary(self):
fixed_salary = 3000
hourly_allowance = 30
total_salary = fixed_salary + self.teaching_hours * hourly_allowance
return total_salary

class Lecturer(Teacher):
def __init__(self, name, gender, birthday, teaching_hours):
super().__init__(name, gender, birthday, "讲师", teaching_hours)

def calculate_salary(self):
fixed_salary = 2000
hourly_allowance = 20
total_salary = fixed_salary + self.teaching_hours * hourly_allowance
return total_salary

if __name__ == "__main__":
professor = Professor("张三", "男", datetime(2003,9,30), 40)
print("教授信息:")
professor.display()
print("月工资:", professor.calculate_salary())

associate_professor = AssociateProfessor("李四", "女", datetime(1970,3,19), 30)
print("\n副教授信息:")
associate_professor.display()
print("月工资:", associate_professor.calculate_salary())

lecturer = Lecturer("王五", "男", datetime(1989,4,25), 20)
print("\n讲师信息:")
lecturer.display()
print("月工资:", lecturer.calculate_salary())
posted @   Hbro  阅读(5)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示