CatalogItem Class
CatalogItem is a generic class that will take two type parameters
T and S. T will represent the type
of a CatalogItem's ID and will be bounded by the Comparable interface.
S will represent the type of a CatalogItem's contained object
and will be bounded by the Media interface that we have created.
CatalogItem must also implement the Comparable interface itself so that we
may sort CatalogItems.
-
Instance variables: Declare a variable,
catalogID, of typeTand a contained object,media, of typeS. -
Constructor: Take in arguments of type
TandSand initializecatalogIDandmediawith these values. -
compareTo Method: Write a compareTo method that simply returns the the
compareTo of the calling object's
catalogIDand the argument object'scatalogID. Why can we assume thatcatalogIDwill have a compareTo method? -
toString Method: Write a toString method that returns the concatenation of
catalogID'stoString with the return values formedia'sgetCreator, getTitle, and getYear methods. Why can we assume thatmediawill have these methods?