6.8
设计高校人员信息包,并完成测试q
# 定义一个基础类 People
class People:
def __init__(self, name, gender, age):
self.name = name
self.gender = gender
self.age = age
def display_info(self):
print(f"Name: {self.name}, Gender: {self.gender}, Age: {self.age}")
# 基于People实现Student类
class Student(People):
def __init__(self, name, gender, age, student_id, admission_time, admission_score):
super().__init__(name, gender, age)
self.student_id = student_id
self.admission_time = admission_time
self.admission_score = admission_score
def display_info(self):
super().display_info()
print(f"Student ID: {self.student_id}, Admission Time: {self.admission_time}, Admission Score: {self.admission_score}")
# 基于People实现Teacher类
class Teacher(People):
def __init__(self, name, gender, age, title, department, working_years):
super().__init__(name, gender, age)
self.title = title
self.department = department
self.working_years = working_years
def display_info(self):
super().display_info()
print(f"Title: {self.title}, Department: {self.department}, Working Years: {self.working_years}")
# 基于Student实现Graduate类
class Graduate(Student):
def __init__(self, name, gender, age, student_id, admission_time, admission_score, research_direction, advisor):
super().__init__(name, gender, age, student_id, admission_time, admission_score)
self.research_direction = research_direction
self.advisor = advisor
def display_info(self):
super().display_info()
print(f"Research Direction: {self.research_direction}, Advisor: {self.advisor}")
# 定义一个接口类,用于在职研究生的接口规范
class OnWorkInterface:
def work_experience(self):
pass
# 实现在职研究生类 GradOnWork,继承自 Graduate 并实现 OnWorkInterface 接口
class GradOnWork(Graduate, OnWorkInterface):
def __init__(self, name, gender, age, student_id, admission_time, admission_score, research_direction, advisor, company, position):
super().__init__(name, gender, age, student_id, admission_time, admission_score, research_direction, advisor)
self.company = company
self.position = position
def display_info(self):
super().display_info()
print(f"Company: {self.company}, Position: {self.position}")
def work_experience(self):
print("Displaying work experience...")