设计两个酒店管理员客房管理的类:一个是Person类,要求有储存房号,客户姓名和身份证号的信息;另一个类是Client类,要求新增客户的订房、退房和消费金额等信息。并给出相关测试算法
时间: 2023-05-28 12:01:50 浏览: 159
Person类的实现:
```python
class Person:
def __init__(self, room_no, name, id_num):
self.room_no = room_no
self.name = name
self.id_num = id_num
```
Client类的实现:
```python
class Client:
def __init__(self):
self.client_list = []
def add_client(self, room_no, name, id_num):
client = Person(room_no, name, id_num)
self.client_list.append(client)
print(f"客户{name}已成功订房{room_no}")
def remove_client(self, room_no):
for client in self.client_list:
if client.room_no == room_no:
self.client_list.remove(client)
print(f"客户{client.name}已成功退房{room_no}")
break
def calculate_bill(self, room_no, spent):
for client in self.client_list:
if client.room_no == room_no:
print(f"客户{client.name}的消费总金额为{spent}元")
break
```
测试算法:
```python
# 测试
client = Client()
client.add_client(101, "张三", "123456")
client.add_client(202, "李四", "234567")
client.calculate_bill(101, 250)
client.calculate_bill(202, 180)
client.remove_client(101)
```
输出结果:
```
客户张三已成功订房101
客户李四已成功订房202
客户张三的消费总金额为250元
客户李四的消费总金额为180元
客户张三已成功退房101
```
阅读全文