Assignment #6: Garbage Collection

A Library class is used to store a collection of Books. You may assume that a Book has an author, title, ISBN number, and publication date with appropriate accesssors (and toString and equals). Equals for books compares ISBN numbers. Further, a Library has a constructor that will initialize it with a collection of books, a findBookByISBN method that returns a book given its ISBN number, and a checkout method to checkout an existing book. Of course, once a book has been checked out of the library, it cannot be checked out until it has been returned. A book is automatically returned to the library if there are no valid references to it. Checking out a book does not affect the result of findBookByISBN.

Implement this spec using weak references (to reclaim books), along the lines of the Foo pool demonstrated in class. Both checking out a book and the reclamation of a book should be constant-time operations. Provide a test program that illustrates the behavior of your library class.

What to Submit

Submit your source code and sample output.