Lab 12 Class
Most of the Lab12 class is provided to you. To complete its definition, you will need to do the following:
- Create an ArrayList of CatalogItems named iPod.
- 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>()
; - Since we are making an iPod catalog, the type parameters for CatalogItem should be Integer and CD, respectively.
- Create an ArrayList of CatalogItems named kindle.
- This will look very similar to the declaration and initialization of iPod, but the CatalogItem type parameters will now be String and Book.
- Create a Scanner object from a FileInputStream over a text file that you have created containing String IDs and Book fields (author, title, and year).
- Your text file should be placed into your Project directory on the same level as your src folder.
- Your text file should be formatted in the following manner:
FirstBookID
FirstBookAuthor
FirstBookTitle
FirstBookYear
SecondBookID
SecondBookAuthor
... - Add elements to kindle by reading four lines from your text file for each iteration.
- Refer to code for adding CatalogItems to the iPod ArrayList. You should be able to add a CatalogItem to your kindle ArrayList in one line of code as well, though it will be pretty lengthy.
- You will be reading four complete lines as Strings, but to create a Book for your CatalogItem, you will need to convert the year String into
an integer. Remember that you can use
Integer.parseInt
to accomplish this.