Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objects Lab Write a class Book to model books. This book object will have two instance variables: a title (String) and authors (Array of Strings).

image text in transcribed

Objects Lab Write a class "Book" to model books. This book object will have two instance variables: a title (String) and authors (Array of Strings). Write a default constructor which sets title to "Test" and authors to null. Write a constructor receiving values for these fields. Lastly, implement getter and setter methods for your instance variables. In "Book", write a method "book ToString", which returms a string with the books information (in the format below. Use " to have a quote character in a string The Lord of the Rings" by J.R.R. Tolkien Nixonland" by Rick Perlstein "Berenstain Bears" by Stan Berenstain & Jan Berenstain Write a class "Bookshelf" to model a bookshelf. This bookshelf object will have two instance variables: size (int) and books (ArrayList of Books). Write a default constructor which sets the size to 2 and initializes the ArrayList. Write a parameterized constructor which receives a single parameter for size and initializes the ArrayList. Write a getter method for the size instance variable. (Don't write a setter method, you can't change the size of a bookshelf after it's been created!) Write a getter method for the books instance variable Rather than a single setter method, write three specific methods to modify the contents of the bookshelf: a public void method addBook which takes a single book parameter and adds it to the shelf variable if there is room in the shelf, a public void method removeBook which takes no parameters and removes the first book on the shelf (the book at position 0 in the books ArrayList), and a public void method emptyBookshelf which takes no parameters and removes all of the books from the shelf (empties the books ArrayList) Neither the "Book" class or the "Bookshelf class can have a main method. If you want to test your "Book" and "Bookshelf classes, you may make a separate class with a main method. You do not need to submit this separate class

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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions

Question

Describe how language reflects, builds on, and determines context?

Answered: 1 week ago