CatalogDriver Class
Most of the CatalogDriver class is provided to you. To complete its definition, you will need to do the following:
- Create an ArrayList of CatalogItems. The type parameter for the catalog items will be a CD.
- If you haven't declared and initialized an ArrayList before, this is how an ArrayList of Strings would look:
List<String> stringList = new ArrayList<String>()
;
Note that the - Note that creating an array list of Books is syntactically legal just as creating an array list of catalog items each of which is of type a Book. Although you won't get a compiler error, both however are not the same and you should keep a note of this in order to avoid bugs.
- Similarly, create another ArrayList of CatalogItems, where each catalog item is of type Book
ArrayList
object is being referred by a List
object.The code after the above declarations in the Driver class sorts the ArrayList by calling the private method sort(). If you have a look at the sort() method, it calls the compareTo() method you wrote for each of the catalog items.