Please write missing statements to make the following method buildMap complete. The buildMap method takes a book array s as the parameter and returns a HashMap instance that consists of a collection of pairs of the key ISBN coupling up with its corresponding book object. public HashMap buildMap(Book[] s) { I/TODO Write the statements here

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
BooksMan import java.util.HashMap; import java.util.ArrayList; class Book{ String title, ISBN; ArrayList authors; public Book (String title, String ISBN, String authors){ this.title = title; this.ISBN = ISBN; this.authors = new ArrayList(); if (authors != null) { String [] authorArray = authors.split(", "); for (int i = 0; i < authorArray.length; i++) { this.authors.add(authorArray[i]); } } } public String getISBN() { return ISBN; } public String getTitle() { return title; } public ArrayList getAuthors() { return authors; } } public class Main { public static HashMap buildMap(Book[] s) { HashMap books = new HashMap(); if (s != null) { // TODO Write the statements here: to manage each book from the parameter array reference to the hashmap } return books; } public static void main(String argv[]) { Book[] bookArray = new Book[4]; for (int i = 0; i < 4; i++) { bookArray[i] = new Book((new Integer(i)).toString(), (new Integer(i)).toString(), "ITSC2214" ); } HashMap books = Main.buildMap(bookArray); System.out.println("The total number of books is " + books.size()); for (int i = 0; i < 4; i++) { System.out.println("Book[" + i + "] is " + books.get((new Integer(i)).toString()).getTitle()); } } }
Oscar has given you a list of books. She is tired of deciding what to read by
author names and now wants to be able to pick them by their unique ISBN
label. Organize this list of books for Oscar!
The books will be given as an array of Book objects. Each book object contains
the information of String title, String ISBN, and String array authors.
A Hash Map will need to be declared that keys each book in the array based on
the ISBN String of each book.
Example:
Book object, titled "Once Upon an Algorithm", authored by Martin Erwid, and
with ISBN = "9780262036634" keys to "9780262036634"
Book object, titled "Java Software Structures", authored by John Lewis and
Joseph Chase, and with ISBN = "9780133250121" keys to "9780133250121"
Let us assume that we already have the Book class defined. The main part
involved in the question is as follows:
class Book{
Transcribed Image Text:Oscar has given you a list of books. She is tired of deciding what to read by author names and now wants to be able to pick them by their unique ISBN label. Organize this list of books for Oscar! The books will be given as an array of Book objects. Each book object contains the information of String title, String ISBN, and String array authors. A Hash Map will need to be declared that keys each book in the array based on the ISBN String of each book. Example: Book object, titled "Once Upon an Algorithm", authored by Martin Erwid, and with ISBN = "9780262036634" keys to "9780262036634" Book object, titled "Java Software Structures", authored by John Lewis and Joseph Chase, and with ISBN = "9780133250121" keys to "9780133250121" Let us assume that we already have the Book class defined. The main part involved in the question is as follows: class Book{
Let us assume that we already have the Book class defined. The main part involved in the question is as follows:
class Book{
String title, ISBN3;
ArrayList<String> authors;
public String getISBN(); //return the ISBN label of a Book object
Please write missing statements to make the following method buildMap complete. The buildMap method takes a
book array s as the parameter and returns a HashMap instance that consists of a collection of pairs of the key ISBN
coupling up with its corresponding book object.
public HashMap<String, Book> buildMap(Book[] s) {
I/TODO Write the statements here
In the built-in JAVA package, you could use the JAVA built-in generic class: HashMap and its methods:
V get 2 (Object 2 key)
Returns the value to which the specified key is mapped, or null if this map
contains no mapping for the key.
put 2 (K key, V value)
Associates the specified value with the specified key in this map.
The JAVA API reference webpage is at https://docs.oracle.com/javase/7/docs/api/e
Transcribed Image Text:Let us assume that we already have the Book class defined. The main part involved in the question is as follows: class Book{ String title, ISBN3; ArrayList<String> authors; public String getISBN(); //return the ISBN label of a Book object Please write missing statements to make the following method buildMap complete. The buildMap method takes a book array s as the parameter and returns a HashMap instance that consists of a collection of pairs of the key ISBN coupling up with its corresponding book object. public HashMap<String, Book> buildMap(Book[] s) { I/TODO Write the statements here In the built-in JAVA package, you could use the JAVA built-in generic class: HashMap and its methods: V get 2 (Object 2 key) Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key. put 2 (K key, V value) Associates the specified value with the specified key in this map. The JAVA API reference webpage is at https://docs.oracle.com/javase/7/docs/api/e
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY