Question 12
The following Java code maps books to the number of times they have been borrowed from a library and classifies them as popular books (borrowed more than 2 times) or less-read books.
import java.util.*;public class Library { TreeSet<String> popularBooks = new TreeSet<>(); TreeSet<String> lessReadBooks = new TreeSet<>(); public boolean isPopular(int count) { return count > 2; } public void classifyBooks(HashMap<String, Integer> bookMap) { for (Map.Entry<String, Integer> entry : bookMap.entrySet()) { // LINE 1: if statement { popularBooks.add(entry.getKey()); } else { lessReadBooks.add(entry.getKey()); } } } public void displayBooks() { System.out.println("Popular Books: " + popularBooks); System.out.println("Less-read Books: " + lessReadBooks); } public static void main(String[] args) { HashMap<String, Integer> bookMap = new HashMap<>(); bookMap.put("W", 4); bookMap.put("X", 1); bookMap.put("Y", 3); bookMap.put("Z", 2);
Library lib = new Library(); lib.classifyBooks(bookMap); lib.displayBooks(); }}Choose the correct option to be filled in place of LINE 1 so that the output is:
Popular Books: [W, Y]Less-read Books: [X, Z]