Example 6
Store Inventory
You run a store and wish to keep track of items in your store. Important information includes name, description, Universal Product Code, and price. There should be methods that allow you to get all pieces of information on the item. You should also be able to change the price of the item. These pieces of information should not be able to be directly accessed by another object.
The item object is a good start, but it doesn’t do everything required to keep track of inventory. Create a new Inventory object that uses the Item object. Then, create new methods so that you can add to and remove items from inventory. Finally, create a report that prints out the name, description, code, price and number in stock. This will require at least three more methods, one to buy items, one to sell items, and a report method. Remember not to let more items get sold than you have in inventory.
Next, create a store, which holds inventory information for every item contained in the store. Each requires a name, the city and 2 digit state code that identifies its location. The store cannot stock more than 100 different items, although you can have more than one of each item in stock.
In order to manage the inventory for the entire store, when you want to buy, sell, set prices, or get any details on specific items in stock, you will need to know either the item’s code, or the position in the inventory array.