Solution Review
Let’s look at the solution to the tasks from the previous lesson.
We'll cover the following...
Task I: Total number of books by an author
The task was to find the total number of books written by an author. Look at the code below.
Look at the header of the authorBooks method at line 3. We make an ArrayList variable, book, at line 6. Then, we traverse all rows of the dataset with a for loop.
Look at line 13. If a record’s author matches with the given author (argument passed), and we haven’t already added the book’s name of that record in book, then we add the book’s name of that record in book.
Lastly, we return the size of book, which is the number of books written by the author.
Task II: All the authors in the dataset
The task was to find the names of all the authors present in the dataset. Look at the code below.
Look at the header of the allAuthors method at ...