Advanced Visual Basic 2010 Chapter 3 Programming Challenge 6 FirstPlay Sports Rental
Create an application named FirstPlay Sports Rental that keeps track of the inventory for a sports rental store.
• The user can input a new rental item and add it to the store inventory.
• The user can select an item’s ID Number from a list and remove the item from the inventory.
• The user can select an item’s ID Number from a list and display the item’s properties.
• When the application starts, it reads an inventory list from a file (text format).
• When the application ends, it writes the inventory list back to the same file.
User Interface Details
Display a single sports rental item in a window, as shown in Figure 3-23. Each item has an ID number; a description; daily, weekly, and monthly rental rates; and the quantity on hand. When the application starts, it reads all item information from a file into a collection (implemented as a Dictionary) and copies the item ID numbers into a combo box on the form. The user can select an ID number from the combo box, and display or remove existing items. The user can also add new items to the collection. When the program ends, it writes the collection to the same file.
The application’s startup form displays inventory items and lets users carry out each of the following actions:
• Input fields for a new rental item, and add that item to the inventory.
• Select an item’s ID Number and remove the item from the inventory.
• Select an item’s ID Number and display the item’s properties.
When the form loads, the combo box should contain a list of all inventory ID Numbers.
Returning to Figure 3-23 for a moment, we see that it shows a new item about to be added to the store inventory. When the Add Current Item button is clicked, the button’s handler creates a new Item object and passes it to the class that handles the store inventory. Figure 3-24 shows an example of searching for an item by ID Number. When the user clicks the Display Item button, the remaining item fields are filled in. When the user clicks the Remove Current Item button, the program confirms the operation with the user, as shown in Figure 3-25. If the answer is yes, the program removes the item identified by the ID Number.
We suggest that the application define three classes: Item, Inventory, and InventoryFile.
• The Item class encapsulates a single inventory item.
• The Inventory class represents a collection that contains all items and provides methods for adding, finding, and removing items. Internally, it should hold the items in a Dictionary object.
• The InventoryFile class is responsible for reading the inventory data from a text file, and writing all Inventory data back to the file.