用Python面向对象写一个宾馆管理系统
时间: 2024-01-05 14:02:39 浏览: 106
好的,宾馆管理系统可以分为以下几个部分:
1. 客房信息管理:包括房间号、房型、价格、状态等属性
2. 顾客信息管理:包括姓名、电话、身份证号、预订房间号等属性
3. 订单管理:包括订单号、顾客信息、房间信息、订单状态等属性
基于以上需求,可以构建以下类:
```python
# 客房信息类
class Room:
def __init__(self, room_number, room_type, price, status):
self.room_number = room_number
self.room_type = room_type
self.price = price
self.status = status
def __str__(self):
return f"房间号:{self.room_number},房型:{self.room_type},价格:{self.price},状态:{self.status}"
# 顾客信息类
class Customer:
def __init__(self, name, phone_number, id_card, room_number=None):
self.name = name
self.phone_number = phone_number
self.id_card = id_card
self.room_number = room_number
def __str__(self):
return f"姓名:{self.name},电话:{self.phone_number},身份证号:{self.id_card},预订房间号:{self.room_number}"
# 订单管理类
class Order:
def __init__(self, order_number, customer, room, status):
self.order_number = order_number
self.customer = customer
self.room = room
self.status = status
def __str__(self):
return f"订单号:{self.order_number},顾客信息:{self.customer},房间信息:{self.room},订单状态:{self.status}"
```
接下来是宾馆管理系统类:
```python
class HotelManagementSystem:
def __init__(self):
self.rooms = [] # 客房信息列表
self.customers = [] # 顾客信息列表
self.orders = [] # 订单信息列表
# 添加客房信息
def add_room(self, room):
self.rooms.append(room)
# 添加顾客信息
def add_customer(self, customer):
self.customers.append(customer)
# 添加订单信息
def add_order(self, order):
self.orders.append(order)
# 根据房间号查询客房信息
def search_room_by_number(self, room_number):
for room in self.rooms:
if room.room_number == room_number:
return room
return None
# 根据订单号查询订单信息
def search_order_by_number(self, order_number):
for order in self.orders:
if order.order_number == order_number:
return order
return None
# 查询所有客房信息
def display_all_rooms(self):
for room in self.rooms:
print(room)
# 查询所有顾客信息
def display_all_customers(self):
for customer in self.customers:
print(customer)
# 查询所有订单信息
def display_all_orders(self):
for order in self.orders:
print(order)
```
以上是一个简单的宾馆管理系统的实现,根据需求可以进行扩展。
阅读全文