设计一个奶茶店的排队叫号系统,给出设计实现的功能描述,将功能描述、编制程序和呈现结果上传。
时间: 2024-02-12 22:04:39 浏览: 182
功能描述:
1. 客人进入奶茶店后,可以通过扫描二维码或输入手机号获取排队号码。
2. 系统会显示当前排队人数和预计等待时间。
3. 客人可以通过自助终端或员工工作台查询自己的排队情况。
4. 员工可以在工作台查看当前排队情况,并将客人的订单信息输入系统。
5. 系统会在客人的订单准备好后发送短信通知客人前来取餐。
程序实现:
以下是使用Python实现奶茶店排队叫号系统的代码示例:
```python
import time
class Queue:
def __init__(self):
self.queue = []
self.count = 0
def enqueue(self, customer):
self.queue.append(customer)
self.count += 1
def dequeue(self):
if self.count == 0:
return None
customer = self.queue[0]
self.queue = self.queue[1:]
self.count -= 1
return customer
class Customer:
def __init__(self, name, phone):
self.name = name
self.phone = phone
self.number = None
self.status = "waiting"
self.arrival_time = time.time()
self.finish_time = None
def __str__(self):
return f"{self.name} ({self.phone})"
class Notification:
def __init__(self):
self.messages = []
def send_message(self, customer):
message = f"Dear {customer.name}, your order is ready for pickup. Please come to the counter."
self.messages.append(message)
# send message to customer's phone number
def get_messages(self):
messages = self.messages
self.messages = []
return messages
class System:
def __init__(self):
self.queue = Queue()
self.notification = Notification()
self.number = 0
def get_number(self, customer):
self.number += 1
customer.number = self.number
self.queue.enqueue(customer)
return self.number
def get_waiting_time(self):
if self.queue.count == 0:
return 0
total_waiting_time = 0
for customer in self.queue.queue:
if customer.status == "waiting":
total_waiting_time += time.time() - customer.arrival_time
return total_waiting_time / self.queue.count
def get_queue_status(self):
return f"Current queue length: {self.queue.count}, estimated waiting time: {self.get_waiting_time()} seconds"
def update_customer_status(self, number, status):
for customer in self.queue.queue:
if customer.number == number:
customer.status = status
if status == "finished":
customer.finish_time = time.time()
self.notification.send_message(customer)
break
def get_notification(self):
return self.notification.get_messages()
system = System()
while True:
print("Welcome to the Milk Tea Shop!")
print("1. Get queue number")
print("2. Check queue status")
print("3. Check order status")
print("4. Finish order")
print("5. Exit")
choice = input("Please select an option: ")
if choice == "1":
name = input("Please enter your name: ")
phone = input("Please enter your phone number: ")
customer = Customer(name, phone)
number = system.get_number(customer)
print(f"Your queue number is {number}.")
elif choice == "2":
print(system.get_queue_status())
elif choice == "3":
number = int(input("Please enter your queue number: "))
for customer in system.queue.queue:
if customer.number == number:
if customer.status == "waiting":
print("Your order is still in progress.")
elif customer.status == "finished":
print(f"Your order is ready for pickup. Please come to the counter. (Finish time: {customer.finish_time})")
break
else:
print("Invalid queue number.")
elif choice == "4":
number = int(input("Please enter the queue number of the finished order: "))
system.update_customer_status(number, "finished")
print("Order finished.")
elif choice == "5":
break
else:
print("Invalid choice.")
print()
messages = system.get_notification()
for message in messages:
print(message)
```
程序实现了客人获取排队号码,查询排队情况,员工更新订单状态和发送短信通知等功能。在代码中使用了队列数据结构来存储排队客人,使用时间戳来计算等待时间和订单完成时间。
运行程序后,可以按照提示选择相应的功能,进行排队和取餐操作。程序还会定时检查订单状态,并发送短信通知客人前来取餐。
阅读全文