2024/5/14

所花时间:1小时

代码行:70行

博客量:1篇

了解到的知识点:

# 教师接口

class Teacher:

    def calculate_salary(self):

        pass

# 教授类

class Professor(Teacher):

    def _init_(self, name, gender, birthdate, teaching_hours):

        self.name = name

        self.gender = gender

        self.birthdate = birthdate

        self.title = "教授"

        self.teaching_hours = 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, birthdate, teaching_hours):

        self.name = name

        self.gender = gender

        self.birthdate = birthdate

        self.title = "副教授"

        self.teaching_hours = 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, birthdate, teaching_hours):

        self.name = name

        self.gender = gender

        self.birthdate = birthdate

        self.title = "讲师"

        self.teaching_hours = teaching_hours

    def calculate_salary(self):

        fixed_salary = 2000

        hourly_allowance = 20

        total_salary = fixed_salary + self.teaching_hours * hourly_allowance

        return total_salary

# 创建教师对象并计算月工资

professor = Professor("张三", "男", "1980-05-15", 80)

associate_professor = AssociateProfessor("李四", "女", "1985-10-20", 60)

lecturer = Lecturer("王五", "男", "1990-12-25", 40)

print(f"{professor.title} {professor.name} 的月工资为:{professor.calculate_salary()}元")

print(f"{associate_professor.title} {associate_professor.name} 的月工资为:{associate_professor.calculate_salary()}元")

print(f"{lecturer.title} {lecturer.name} 的月工资为:{lecturer.calculate_salary()}元")

posted @ 2024-05-14 21:43  为20岁努力  阅读(17)  评论(0编辑  收藏  举报