CatalogItem Class
CatalogItem is a generic class that will take a type parameter
S
which will be bounded by the Comparable interface.
S
represents the type of a CatalogItem's contained object
and must extend the Media interface that we have created.
CatalogItem must also implement the Comparable interface itself so that we
may sort CatalogItems.
Hence, the CatalogItem
class would be declared as follows :
public class CatalogItem<S extends Media> implements Comparable<CatalogItem<S>> { //your code }
-
Instance variables: Declare a contained object,
media
, of typeS
. -
Constructor: Take in an argument of type
S
and initializemedia
with this value. -
compareTo Method: Write a compareTo method that simply returns the
compareTo() result of the calling object's media's
id
and the argument object's media'sid
. Why can we assume that both Book's and CD'sid
will have a compareTo method? -
toString Method: Write a toString method that returns the concatenation of
media's
getId, getCreator, getTitle, and getYear methods. Why can we assume thatmedia
will have these methods?