实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty和Staff。 具体要求如下: (1)Person类中的属性有:姓名name(String类型),地址address(String类型),电话号码telphone(String类型)和电子邮件地址email(String类型); (2)Employee类中的属性有:办公室office(String类型),工资wage(double类型),受雇日期hiredate(String类型); (3)Faculty类中的属性有:学位degree(String类型),级别level(String类型); (4)Staff类中的属性有:职务称号duty(String类型);Python、代码
时间: 2023-12-26 11:04:51 浏览: 90
以下是Python中实现Person、Employee、Faculty和Staff类的代码:
```python
class Person:
def __init__(self, name, address, telphone, email):
self.name = name
self.address = address
self.telphone = telphone
self.email = email
class Employee(Person):
def __init__(self, name, address, telphone, email, office, wage, hiredate):
super().__init__(name, address, telphone, email)
self.office = office
self.wage = wage
self.hiredate = hiredate
class Faculty(Employee):
def __init__(self, name, address, telphone, email, office, wage, hiredate, degree, level):
super().__init__(name, address, telphone, email, office, wage, hiredate)
self.degree = degree
self.level = level
class Staff(Employee):
def __init__(self, name, address, telphone, email, office, wage, hiredate, duty):
super().__init__(name, address, telphone, email, office, wage, hiredate)
self.duty = duty
```
使用方法:
```python
person = Person("Tom", "123 Main St.", "555-1234", "tom@email.com")
employee = Employee("John", "456 Oak Ave.", "555-5678", "john@email.com", "A101", 50000, "01/01/2022")
faculty = Faculty("Mary", "789 Pine Rd.", "555-9876", "mary@email.com", "B202", 70000, "01/01/2021", "PhD", "Associate")
staff = Staff("Bob", "321 Elm St.", "555-4321", "bob@email.com", "C303", 40000, "01/01/2020", "Manager")
```
阅读全文