Comp 170 Lab 7 - DoME (Database of Multimedia Entertainment), Oct 29

The DoME program is the central example of chapters 8 and 9; 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 essentially represents version 2, but with some use of inheritance for print(), and also for the keywords() method. You are to do the following:

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. 

There are two ways to approach the print() method:

Note that, either way, although the main program appears to be calling Item.print()  for each item, in fact due to the most-specific-method rule, the appropriate specific-class print() method is called (that is, CD.print() for CDs, DVD.print() for DVDs, etc). Item.print() is only called if you do so explicitly, with super.print(), or if you fail to provide a specific-class version of print(). If you take the first apprach above, Item.print() wouldn't have to do anything at all (though it must still be there).

For searchAll(), note that we are again using inheritance. Each class has a method keywords() (check that it does! fix any problems!) that returns a string of keywords appropriate for that class; for example, DVD.items returns the string director + " " + star. Item.keywords() returns the empty string; it is in effect a "placeholder" for the specific-class versions. Each time searchAll() calls keywords(), while it again appears as if Item.keywords() is called, in fact the appropriate specific-class version (eg DVD.keywords()) is invoked. This version then returns the appropriate keyword string for that class of object.

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

Note that the list() method is just a special case of searchTitle() where you're searching for the empty string (so everything matches).

Email me your completed project.