class Person:
    def __init__(self, name, address, phone, email):
        self.name = name
        self.address = address
        self.phone = phone
        self.email = email

    def __str__(self):
        return f'Person: {self.name}'

class Student(Person):
    FRESHMAN = '大一'
    SOPHOMORE = '大二'
    JUNIOR = '大三'
    SENIOR = '大四'

    def __init__(self, name, address, phone, email, class_status):
        super().__init__(name, address, phone, email)
        self.class_status = class_status

    def __str__(self):
        return f'Student: {self.name}'

class Employee(Person):
    def __init__(self, name, address, phone, email, office, salary, hire_date):
        super().__init__(name, address, phone, email)
        self.office = office
        self.salary = salary
        self.hire_date = hire_date

    def __str__(self):
        return f'Employee: {self.name}'

class Faculty(Employee):
    def __init__(self, name, address, phone, email, office, salary, hire_date, office_hours, level):
        super().__init__(name, address, phone, email, office, salary, hire_date)
        self.office_hours = office_hours
        self.level = level

    def __str__(self):
        return f'Faculty: {self.name}'

class Staff(Employee):
    def __init__(self, name, address, phone, email, office, salary, hire_date, title):
        super().__init__(name, address, phone, email, office, salary, hire_date)
        self.title = title

    def __str__(self):
        return f'Staff: {self.name}'

class MyDate:
    def __init__(self, year, month, day):
        self.year = year
        self.month = month
        self.day = day

person = Person('John Doe', '123 Main St', '123-456-7890', 'johndoe@example.com')
student = Student('Jane Smith', '456 Elm St', '987-654-3210', 'janesmith@example.com', Student.SOPHOMORE)
employee = Employee('Tom Johnson', '789 Oak St', '555-555-5555', 'tomjohnson@example.com', 'A101', 50000, MyDate(2022, 1, 1))
faculty = Faculty('Alice Williams', '321 Pine St', '111-111-1111', 'alicewilliams@example.com', 'B202', 60000, MyDate(2021, 12, 31), '9:00 AM - 5:00 PM', 'Professor')
staff = Staff('Bob Brown', '654 Cedar St', '222-222-2222', 'bobbrown@example.com', 'C303', 40000, MyDate(2023, 5, 1), 'Assistant')

print(person)
print(student)
print(employee)
print(faculty)
print(staff)
Python面向对象编程:设计Person类及其子类

原文地址: https://www.cveoy.top/t/topic/dSwf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录