Solution Review
Let’s look at the solution to the tasks from the previous lesson.
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.
Press + to interact
Driver.java
DatasetReader.java
Book.java
import java.util.List;class Driver {public static void main(String[] args) {DatasetReader reader = new DatasetReader();List<Book> books = reader.readDataset("data.csv");String authorName = "J.K. Rowling";Book bookInstance = new Book(null, null); // Placeholder instance to access the methodint bookCount = bookInstance.countBooksByAuthor(books, authorName);System.out.println("Total number of books by " + authorName + ": " + bookCount);}}
Code explanation:
The following section provides an overview of the working of each class.
Driver.java: This is the main class that reads the dataset, counts the number of books by author, and prints the results.
DatasetReader.java: It handles reading the dataset from a CSV file and creating Book
objects.
Book.java: It represents a book with title and author attributes.
Task II: All the authors in the dataset
The task was to find the names of all the ...