CSCI 180/181 Lab 4

handin name for today's lab is lab4 The lab is due on 11 February 2008 at 23:59

Objectives

Loops and ArrayList

In class, we introduced loops and the ArrayList using a simple Library class and our Book class from lab 2. We did the following:
  1. Created a project called library-project with a new Library class and our lab 2 Book class.
  2. Added a field that is an ArrayList<Book> to hold our books.
  3. Added a method called addBook that assigns a reference number to a book and adds a Book to the library.
  4. Added a method called displayAll to print info about all books in the library

In this lab, we will add methods to the Library to continue practicing with loops and ArrayLists.

  1. Add a method Book findBook(String author, String title) to find a book based on author and title. If no book exists with that author and title, return null. Otherwise, return the book.

    Remember that strings are compared using the .equals method (e.g. if (foo.equals(currentBook.getAuthor()))

  2. Add a method boolean anyBooks(String author) to the Library class that returns true if the library holds any books by the given author, or false if not.

  3. Add a method ArrayList<Book> findAuthor(String author) to the library that searches the library to find books by the given author. The method returns either a reference to an ArrayList holding the references to these books or null if no books are found by the author.

  4. Following the example of removeNote from the notebook projct of chapter 4 (and seen on page 88 of the text), add a void removeBook(int i) method to the Library that is given the index of a book and removes it from the library.

  5. Add a method void removeBook(String author, String title) that removes the specified book from the library (or does nothing if it is not in the library).
handin the Library class.