Step 6: 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 type T and a contained object, media, of type S.
- Constructor: Take in arguments of type T and S and initialize catalogID and media with these values.
- compareTo Method: Write a compareTo method that simply returns the the compareTo of the calling object's catalogID and the
argument object's catalogID. Why can we assume that catalogID will have a compareTo method?
- toString Method: Write a toString method that returns the concatenation of catalogID's toString with the return values for media's
getCreator, getTitle, and getYear methods. Why can we assume that media will have these methods?