Question: Write this code in Java language 1 . Implement a Book class which has the following members: Three Private member variables: title ( String )
Write this code in Java language
Implement a Book class which has the following members:
Three Private member variables: title String releaseYear int isNew Boolean
Public methods: two constructors: one noargument constructor and one overloaded constructor which takes three parameters in the following order: String, Boolean, int
Implement a Bookshelf collection class. This is a collection of objects from the Book class. It has the following members:
two private member variables: bookArray Book numItemsint
a constructor that takes an integer as parameter to initialize the size of the array bookArray
Assuming that the bookshelf list is unordered, write an insert method for the Bookshelf class. This is a void method that takes a Book object as parameter.
Create a driver class named BookshelfDriver.
Declare an object of type Bookshelf inside the driver class named myLibrary and add the following two book to mylibrary:
Book : How to Catch a Dinosaur isNewtrue
Book : I am Enough isNewtrue
Add two additional books of your choice
In your Book class, create a toString method that returns the values of the private member variables separated by a tab.
In the Bookshelf class, create a toString method. This should return a string that includes the header Current Book List followed by the information about all the books in the array on the subsequent lines you will need to call the toString method of the Book class
In the Bookshelf class, update the insert method to make sure the book collection stays organized. We want the books to be listed from newest to oldest. Therefore, when adding a new book, we must compare the releaseYear of the new book with the releaseYear of existing books and insert it in the correct spot to maintain the sorted order. This way, whenever you look at the collection, you'll see the latest releases first in the array. Feel free to use or not use a helper method.
Create a void method called remove in the Bookshelf class. This method takes one input parameter of type Book. The method then searches the collection for the first object that equals the input object and deletes its occurrence if found. After the item has been deleted, the list must still be maintained in order.
Test it in the driver class to make sure that it maintains the order of the collection.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
