Try It Yourself: using a book collection
Classes Used
Note: only relevant methods are listed.
Library class
void addBook(Book book)
Adds the given Book object to the library.
boolean removeBook(Book book)
Removes the given Book object from the library returning true if the
book was in the library (prior to removal) and false otherwise.
BookCollection getBookCollection()
Returns a BookCollection object containing all the Book objects in
the library.
BookCollection class
boolean hasMoreBooks()
Determines if additional Book objects are in the collection.
Book nextBook()
Returns the next Book object in the collection.
Book class
String getTitle()
Returns the title of the Book object.
String getAuthor()
Returns the author of the Book object.
int getYear()
Returns the year of publication of the Book object.
int getPages()
Returns the number of pages of the Book object.
String getISBN()
Returns the ISBN of the Book object.
String getPublisher()
Returns the publisher of the Book object.
boolean isCheckedOut()
Returns true if the Book object has been checked out and false
otherwise.
void checkOut(String name)
Checks the Book object out to the given name.
void checkIn()
Checks the Book object back in.
Questions
Write a code fragment to:
- Report the title of every book in the library that is checked out.
- Find out the number of books with the title given in the variable
title.
- Find all the books written by the author given in the
variable
author.
- Check out the book titled Intro to CS to Pat Smith.