写一个车位管理界面代码
时间: 2024-02-24 13:56:16 浏览: 64
好的,以下是一个简单的车位管理界面的代码:
```python
class ParkingLotUI:
def __init__(self, parking_lot):
self.parking_lot = parking_lot
def display_menu(self):
print("Welcome to the Parking Lot Management System!")
print("1. Park a vehicle")
print("2. Unpark a vehicle")
print("3. View available spaces")
print("4. View occupied spaces")
print("5. View revenue")
print("6. Exit")
def run(self):
while True:
self.display_menu()
choice = input("Please enter your choice: ")
if choice == "1":
result = self.parking_lot.park_vehicle()
print(result)
elif choice == "2":
hours = int(input("Please enter the number of hours parked: "))
result = self.parking_lot.unpark_vehicle(hours)
print(result)
elif choice == "3":
available_spaces = self.parking_lot.get_available_spaces()
print("Available spaces: {}".format(available_spaces))
elif choice == "4":
occupied_spaces = self.parking_lot.get_occupied_spaces()
print("Occupied spaces: {}".format(occupied_spaces))
elif choice == "5":
revenue = self.parking_lot.get_revenue()
print("Total revenue: ${:.2f}".format(revenue))
elif choice == "6":
print("Thank you for using the Parking Lot Management System!")
break
else:
print("Invalid choice. Please try again.\n")
```
这个类实现了一个简单的控制台界面,允许用户使用停车场收费系统的各种功能。在每个选项下,它会调用停车场类的相应方法,并显示结果。当用户选择退出选项时,程序将停止。
你可以根据需要对这个界面进行修改和扩展,例如添加输入验证和错误处理等功能。
阅读全文