Overview

In this lab, you will add exception handling to a program that keeps track of the inventory of items that a wizard can carry.

Instructions

Sample console output if the program can't find the inventory file

The Wizard Inventory program
COMMAND MENU
walk - Walk down the path
show - Show all items
drop - Drop an item exit
Exit program

Could not find inventory file!
Wizard is starting with no inventory.
Command: walk
While walking down a path, you see a crossbow.
Do you want to grab it? (y/n): Y
You picked up a crossbow.

Command: show
1. a crossbow

Command: drop
Number: x
Invalid item number.

Command:

Specifications

  • This program should read the text file named wizard_all_items.txt, which is attached to this Dropbox, that contains all the items a wizard can carry.
  • When the user selects the walk command, the program should randomly pick one of the items that were read from the text file and give the user the option to grab it.
  • The current items that the wizard is carrying should be saved in an inventory file. Make sure to update this file every time the user grabs or drops an item.
  • The wizard can only carry four items at a time. For the drop command, display an error message if the user enters an invalid integer or an integer that doesn't correspond with an item.
  • Handle all exceptions that might occur so that the user can't cause the program to crash. If the all items file is missing, display an appropriate error message and exit the program.
  • If the inventory file is missing, display an appropriate error message and continue with an empty inventory for the user. That way, the program will write a new inventory file when the user adds items to the inventory.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.