Homework 9 - The Wine Cellar
Due: Wednesday, October 8, 2003

The Assignment

This assignment asks you to model a wine cellar. To do this, you should model the WineCellar, itself, as well as a bottle of Wine. You should also implement a menu and appropriate exceptions.

The Wine

When a bottle of Wine is created, it has four characteristics:

After creation, the wine can be opened, and the characteristics can be viewed. But, the other properties cannot be changed -- at least absent fraud.

Additionally, Wine should support the toString() method.

The WineCellar

The WineCellar holds bottles of Wine. When a WineCellar is built, it is configured to hold a certain maximumNumberOfBottles, with each bottle in a unique slot. Each of these slots is numbered and the lower numbered slots are closest to the entrance. The highest numbered slots are closest to the rear of the cellar.

When a new bottle is addeded to the celler, it should be added in the first open slot -- after the other bottles of wine. When adding, the number of the slot in which the Wine bottle is placed should be returned, so the user can find it again.

Any bottle of wine, given its slot number, can be examined. This should return a String containing all of the properties of the Wine. Additionally, we observe that people are often interested in the same bottles of Wine again and again. So, in order to shorten the person's walk through the cellar, the bottle of Wine is swapped with the one before it, making it a little closer to the door for next time. If the bottle is already in the closest slot to the door, it, of course, should not be swapped with anything.

A bottle of Wine can, of course, be removed for drinking. To remove a bottle, one need only know its slot number. When removing a bottle of wine, the next bottle closer to the door, if any, should be moved into its slot. As before, this means that when the removed bottle is replaced, it will be replaced into the slot one closer to the door, if available.

After being removed, a bottle can be replaced into its proper slot. To replace a bottle, the user provides the bottle and the proper slot number -- which is, unless it was previosly in slot 0, one less than its old slot number. Unfortunately, while this bottle was removed, another bottle may have been swapped into its otherwise proper slot. If this happens, it should be placed into the next highest available slot.

The toString() method should return a neat list of the Wine in the cellar, wihtout listing empty slots.

If an invalid slot number is provided, an InvalidSlotNumberExceptionshould be thrown. If a bottle of Wine is occupying the last slot of the cellar and an an attempt is made to add an additional bottle of Wine, a CellarIsFullException should be thrown.

The Menu

You should also write a menu that allows the user to createAndAddABottle, examineABottle, getABottle, replaceABottle, and listBottles.