Modeling a Library


This program models a library that allows user to search its inventory of books based on keywords (i.e., any words that match any in the book's author or title). This can be seen as a small step towards building something like amazon.com

There are several classes as part of this project, but the two classes you will work with are Book and Library. Complete the following exercises in order to make the library program functional.

  1. Complete the method initialize in the class Library such that it creates a Book object based on the data in a file of book information and then adds it to the library's inventory by calling the method insertBook. The format of the book data in the file is such that each book is represented by three lines: the title, the author, and the year.
     
  2. Complete the method equals in the class Book such that it returns true only if both books have the exact same title and author, and false otherwise.
     
  3. Explain how the method insertBook in the class Library works. To help your explanation, draw a picture of the instance variable myInventory and show how it is updated in both the true and false cases of the conditional after each call made using this example data.
     
  4. Complete the method findWordIn in the class Book such that it returns true if any whole word in original matches keyword, and false otherwise. For example, if one of the keywords is "love", then it should not match the word "glove" because it is a different word that just happens to contain the keyword as part of it. Note, you do not need to worry about punctuation when comparing words.
     
  5. Complete the method findBooks in the class Library such that it returns a list of all books in the inventory that match the given keywords (i.e., by calling the Book method matches).
     
  6. Explain how the method matches in the class Book works. Give some test cases that would effectively check that this method works correctly.