Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

Discuss the need to split data into test and training data.

Answered: 1 week ago

Question

What are the purposes of promotion ?

Answered: 1 week ago

Question

Define promotion.

Answered: 1 week ago

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

=+Trainers from headquarters? Local trainers? Independent trainers?

Answered: 1 week ago