To start this lab, download this zip file.
Lab 25 - Managing State
For this lab you will write a program named reservations.py
that manages scooter reservations for a small scooter-rental company. They are pretty small—only two scooters so far—but with your help they hope to scale soon!
The program should display menus and prompts as demonstrated in the following example:
python reservations.py test_files/inventory.json
What would you like to do?
(0) List items
(1) Check item in/out
(2) Quit
Option: 1
Which item do you want to check in/out?
(0) Red Scooter
(1) Blue Scooter
Option: 0
What would you like to do?
(0) List items
(1) Check item in/out
(2) Quit
Option: 0
[Checked Out] Red Scooter: Red scooter. Has battery.
[Available] Blue Scooter: Battery-powered scooter.
What would you like to do?
(0) List items
(1) Check item in/out
(2) Quit
Option: 2
Hint: use the prompt_menu
function from class.
When the user selected Check item in/out, the status of that item should toggle: checked-out items are now checked-in, and checked-in items are now checked-out.
Your program should take one argument that is the name of the starting inventory JSON file. You should load your initial state from this file.
Every time an item is checked in or out, you should save the state of your inventory to the provided inventory file.
Tip: when a test fails, use PyCharm’s “Click to see difference” link in the error message to see a clean side-by-side comparison of your program’s input/output compared to what was expected. Note that the comparision will truncate the expected output once it no longer matches your program output.
Grading
You get 5 points for each test that passes. The tests progressively test more and more elaborate use-cases of the program:
- Quit
- List inventory
- Checkout and item
- Checkout, checkin
- Checkout both items
- Run the program multiple times