9. A Polymorphic Video Store
Your friend Electronic Eddie has decided to open a business that rents movies and
games. Unfortunately, Eddie has very little startup money and cannot afford to buy the
latest software package to manage his inventory. As a programmer without peer, you
have come to Eddie’s rescue and have volunteered to write a system for his business.
Your ! rst step is to design a class hierarchy that includes the following classes:
sim23356_ch13.indd 626 12/15/08 7:00:36 PM
• Item (abstract) with the following attributes:
a ! ve-digit ID number ( String )
a title ( String )
rental price ( double )
status: true if in stock, false if currently rented ( boolean )
the current renter’s name ( String ).
The methods of Item might be the standard getter and setter methods as well as
an abstract method
void display()
• Game (extends Item) with the following additional attributes:
manufacturer: e.g., Nintendo, Gameboy, etc. ( String )
age level: an integer from 3 to 16, 16 signi! es 161 ( int )
• Movie (extends Item) with the following additional attributes:
playing time in minutes ( int )
rating : G, PG, PG13, or R ( String )
format: ‘V’ for VHS cassette, ‘D’ for DVD ( char )
Each class implements a display method that prints all the data of the invoking
Once you have implemented the preceding classes, you should design and
implement a class that utilizes the Item hierarchy. Your system should be menu-
driven and include the following options:
a. Check out an item.
Your system should query the user for the ID number of the item and the renter’s
name. If the item is already checked out, your system should say so.
b. Check in an item.
Your system should ask for the ID number of the item. If it is already checked in,
indicate that.
c. Search for an item by ID number to determine whether it is in stock.
You should use binary search for this option. Consequently, all rental items are
kept sorted by ID number.
d. Search for an item by title.
Since the rentals are not sorted by title, you might use sequential search here.
e. Display the entire inventory, sorted by ID.
f. Add a new item to the inventory.
g. Delete an item from the inventory (equivalent to selling a used video or game).
Ask for the ID number of the item to be deleted. If the ID doesn’t match one of
the items in inventory, a message should be printed.
h. Display the menu.
When the program begins, the program should obtain data for each item from a
! le, and store the data in an array sorted by ID number. When the program exits,
the current data should be written back to a ! le.