Comp 170 Lab 8 - DoME (Database of Multimedia Entertainment), Oct 25

The DoME program is the central example of chapter 8; it is a simple database for a combined library of DVDs and CDs. You can create entries of either type, and print them out (CDs first, then DVDs).

The version you are to work with is here. It is a transitional version: it uses inheritance for the basic classes, but (to avoid casts) keeps separate ArrayLists for CDs and for DVDs. You are to add the following features:

The base Item class has fields title, playingTime, gotIt, and comment. Every derived class will thus inherit these. In the Book class constructor, set the playingTime to 0. Do something similar for Game. Note that this is not entirely logical.

Class Book should have an additional author field of its own. Games should have fields for publisher and numPlayers (an int). Create appropriate accessors for these additional fields and a print method. Note that Book.print and Game.print will print fields from the base class Item, like in CD and DVD, but you must call the appropriate accessors for those fields.

To create the Book and Game classes, click on the New Class... button, cut out the contents of the template BlueJ suggests for the contents, paste in the contents of the DVD or CD class, and then edit appropriately.

To allow books to be contained in the database, add an ArrayList field books and a method addBook. Do the same for games. Adjust list so that things are listed in order CD, DVD, Book, Game.

To search the items for a given string srchkey, use the contains(String s) method of the String class:

     title = dvd.getTitle();	// or book or cd
if (title.contains(srchkey))
It is much better if you do the search in a case-insensitive way. To do that, you have to convert both the title and srchkey to, say, lower case:
     title = title.toLowerCase();
srchkey = srchkey.toLowerCase();
Does this change the title permanently? Change srchkey to lower case only once, at the beginning, not once each time through the loop!

Model your search loops (four of them, one each for CDs, DVDs, and Books) after the loops in list. Actually, list is just a special case of search where you're searching for the empty string: every title contains that and thus every item will print.

Email me your completed project.