Question: A Library uses an ArrayList to keep track of Book objects. You will write a Library class. The Book class is given here. class Book

A Library uses an ArrayList to keep track of Book objects. You will write a Library class. The Book class is given here.

class Book { private String title; public Book(String theTitle) { title = theTitle; } public String getTitle() { return title; } } 

A Library has a constructor that takes no parameters. Remember, it must initialize the instance variable.

Supply the following methods to the Library class:

addBook() adds the specified Book to the Library.

contains() determines if a Book of the given title is in the Library. Returns true if the given title is in the Library. Otherwise, false.

Here is a tester.

class LibraryTester { public static void main (String [] args) { Library lib = new Library(); lib.addBook(new Book("Brave New World") ); lib.addBook(new Book("Bambi")); lib.addBook(new Book("The Hobbit")); System.out.println(lib.contains("Bambi")); // prints true System.out.println(lib.contains("The Hobbit")); // prints true System.out.println(lib.contains("Animal Farm")); // prints false } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!