Search⌘ K

Solution Review

Explore how to apply Java object-oriented programming concepts by breaking down a project analyzing Amazon's Top 50 Bestselling Books dataset. Learn to create and use classes to read data, count books and authors, retrieve book titles by author, filter by user rating, and list book prices. This lesson helps you understand practical OOP structures by implementing real-world data handling tasks.

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.

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 method
int 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 ...