Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started