Question: Java. In this week's lab you will create a Book class, a Bookshelf class, and test them using a main method in a ShelfTest class.
Java.
In this week's lab you will create a Book class, a Bookshelf class, and test them using a main method in a ShelfTest class.
The Book class should contain a book's title, author, and copyright year. It should have a constructor setting all three properties and a toString() method which creates a String object that looks like "The Hobbit", J.R.R. Tolkien, 1937
The Bookshelf class should contain an array of books:
The constructor should take the maximum number of books to store as its parameter.
The class should contain an add() method that takes a Book object as its parameter.
The class must also have a contains() function that takes the name of the book and returns the index of that book if found, or -1 if not found.
There must be a remove() function. It takes the index as a parameter, removes the book from the shelf and returns a reference to it if it exists on the shelf, or null if it does not.
There must be a quantity() function. This returns the number of Book objects actually present in the array (not the capacity).
The toString() method should look something like "Bookshelf with 2 books: The Hobbit, Neuromancer"
The ShelfTest class should have a main() function which tests all of the functions in Bookshelf above. You will likely need to create a few different Bookshelf objects in the main and load them up to properly test the methods.
Remember that each of your three classes must have javadoc comments on the class itself along with all non-getter, non-setter functions.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
