In this lab, we’ll enhance the TicketManager program by adding a user interface that allows dynamic interaction with the ticketing system through a command-line menu. This lab will consolidate your understanding of how to apply object-oriented design to create practical, user-friendly applications.
Ensure that you are signed into your GitHub account
Join the GitHub Classroom and accept this assignment: Project 12 - Inventory System
Clone the repository to your computer using GitHub Desktop or open it online using Codespaces
Recall that top-down design involves planning the overall structure of a program before focusing on specifics. For our ticketing system, we'll first outline the functions required to interact with the TicketManager facade, such as adding, updating, and removing tickets, as well as displaying the ticket inventory. A great way to do this is through planning your menu system.
Notice the variable actions above. It is a dictionary where we can assign numerical menu choices (1-4) to the four different function in our program.
To add our first menu item "Add Ticket" we simply create the function and add it to the actions dictionary.
Our function will be callled add_ticket_ui as it is adding a user interface to our already existing facade method add_ticket.
actions = { '1': add_ticket_ui }
def add_ticket_ui(manager):
name = input("Enter ticket name: ")
event_date = input("Enter event date (YYYY-MM-DD): ")
price = float(input("Enter ticket price: "))
ticket = Ticket(name, datetime.datetime.strptime(event_date, '%Y-%m-%d').date(), price)
if manager.add_ticket(ticket):
print("Ticket added successfully.")
else:
print("Failed to add ticket.")
elif choice in actions:
actions[choice](manager)
If the number chosen in the menu is in the dictionary (in this case '1'), then access the matching value (add_ticket_ui).
Notice it has (manager) at the end. The result is you get add_ticket_ui(manager), calling the function and passing manager into it.
If we continue adding functions to the program and including them into the actions dictionary we will arrive at a complete program, as below:
Open lab3.py
Complete the following activities:
Import the Item class from lab1.py
Define the InventoryManager class as a facade to handle the inventory operations.
It should include methods to add, remove, update, and display items in the inventory.
Create instances of the Item class and InventoryManager, then demonstrate their usage.
E.g. add items to the inventory, remove items, update items, and display the inventory.
Commit and push your code