Goals: The goals of this lab is to learn how to work with parametric data types.
In the previous exercise we have defined two lists of items, but the only difference between them was the type of data the list contained.
In this part of the lab we will abstract over the data type the lists contain.
Start with a new project Lab7a and import into it the files saved in Lab7a.zip.
You should have the following files, where the IlO file contains a parametrized definition of a list of items of the type given by the parameter T:
Run the program and read the code.
Make an example of a list of books that contains four books. Make an example of a list of songs that contains four songs.
Design the method for the classes that represent a list of data items that counts the number of items in the list.
Every class in Java extends the class Object that among other things defines the method with the signature String toString() that produces a String representation of the object. The default implementation is basically useless. Override this method in the classes Book and Song by designing a method that produces a String that shows the book or song title, and the values of the other fields as well.
Design the method stringList in the classes that represent a list of items that produces a list of String representations of the objects in the list.
Add to the file that defines the ISelect interface the definition of a class BookByPrice that represent a predicate that selects all books that have the price in the given range (low <= price <= high), and another one SongsBy that selects all books by the given artist. Make sure you have tests and examples.
Design the method filter for the classes that represent a list of items that consumes a predicate (an instance of the class that implements ISelect interface and produces a list of all items in this list that satisfy the given predicate.
Note: You probably won’t get to this part. You will do it at home as a homework assignment, but could start thinking about it now.
Rewrite the code from the first part of this lab so that it uses a parametrized list of items for the list of Personss and the list of Accounts.