AP Computer Science – Quiz Involving Multiple Classes
This quiz will involve the writing of three classes to
handle information about a book club. A book club will consist of people who
each have their own library of books (their own private collection of books).
Classes you will
write:
- A Book
Class – maintains the following information about a book:
private String title; //Title of book
private String author; //Author of book
private int numPages;
//Number of pages in book
- A BookLibrary Class – maintains
the following information about a library of books:
private String owner; //Name of owner of the library
private int numBooks;
//Number of books in the library
private ArrayList bookList<Book>
(); //An ArrayList of Book objects (contains all books in the library)
- A BookClub Class –
maintains the following information about a book club:
private ArrayList clubList<BookLibrary>(); //An ArrayList
with a BookLibrary
object for each member of the club
Here are the methods
that you must write for each class (on your own paper):
Book Class
- Default Constructor (sets empty title, author,
0 for pages)
- Initalize Constructor (title, author, pages)
- String getTitle()
// returns title of book
- String getAuthor()
// returns author of book
- int getNumPages
// returns number of pages in book
- String toString()
// displays the book title, author, pages (see example below)
"The
End of an Era"
by
Wendell Gilliam,
346
pages
BookLibrary Class
- Default Constructor (parameter is file
path used to access the text file which loads owner, number of books and
then title, author, number of pages for each book in library)
- String getOwner()
// returns owner of library
- int getNumBooks()
// returns the number of books in library
- Book getBook(int i)// returns book i from the library
- void addBook(Book
b) //adds book b to the library
- void removeBook(String
t) //removes the book with title t
from the library
- int getNumBooksByAuthor(String
auth) // returns the number of books in library by author auth
- void showAllByAuthor(String
auth) // displays the titles of all books in the library by the author auth or “none” if there are
none(see example below)
Books
in library by Wendell Gilliam:
"The
End of an Era"
"Farewell
to Reality"
"When We Were Wild"
OR
none
- String toString()
// displays the library owner, number of books and each book in the library (see example below)
Owner:
Sarah Bellum
Books:
8
Book
List
"The End of an Era" by Wendell Gilliam, 346 pages
"That Was All He Said" by Grace LeFleur, 278 pages
etc...
BookClub Class
- Default Constructor (Creates an empty ArrayList of type BookLibrary)
- void addLibrary(BookLibrary lib) // adds BookLibrary
lib to the ArrayList
- BookLibrary getLibrary(int i) // returns library i from the ArrayList
- Book getBook(int i, int
n) // returns book n from library
i from
the ArrayList
- int getnumMembers()
// returns the number of members in the club
- int getTotalNumBooks()
// returns the total number of books in all libraries in the club
- int getNumUniqueBooks()
// returns the number of unique books in all libraries in the club
- int getNumBooksByAuthor(String
auth) // returns the number of books in all libraries by author auth (duplicates OK)
- void showAllOwnersOfTitle(String
title) // displays the names of all club members who have a book with the
title title
(see example below) or “none”
Club
members who own the book The End of an Era:
Wendy
Stanfield
Brandy Weinstein
OR
Club
members who own the book Oh So Sweet!:
none
- void uniqueClubBookList()
// displays a list of all uniquely titled books in
all member’s libraries (does not allow for duplicates)
- String toString
// displays the owner and number of books for each library in the book
club (see example below)
Owner
1: Wendy Stanfield, Books: 9
Owner
2: Allan Benjamin, Books: 5
Owner
3: Brandy Weinstein, Books: 4
Owner
4: Juan Ramirez, Books: 6
Total
Books in Club: 24
Unique
Books in Club: 17