The goal of this is to create two classes BookstoreBook and LibraryBook that both extend the class Book. The class Book is to be made abstract and to have these private attributes: author: String tiltle: String isbn: String To the Book class, add the abstract method: public String getBookType(); - The BookstoreBook has an additional data member to store the price of the book, and whether the book is on sale or not. If a bookstore book is on sale, we need to add the reduction percentage (like .2 off...etc). For that, add double price, boolean onSale and double saleRate as private fields to the BookstoreBook class. Obviously, saleRate is 0.0 when onSale is false. - In the LibraryBook class, we add Subject and callNumber as String. The call number is automatically generated by the following procedure: The callNumber has the format S.XX.YYY.C, where S is the subject code. The list of subject codes is provided at the end of this document, XX is the floor number that is randomly assigned (our library has 15 floors: 01, 02, ...15), YYY are the first three letters of the author’s name (we assume that all names are at least three letters long), and C is the last character of the isbn. For example, Q.09.JON.T is the call number for a Science book that is located on the 9th floor of the library and whose author’s name starts with JON. The isbn of that book ends with the character T. - In each of the three classes mentioned above, add the setters, the getters, at least two constructors (of your choosing). Override the toString method in the class Book to return a string containing the isbn, author and the title. In the BookstoreBook and LibraryBook classes, override the toString to add the additional information to the returned string, using super.toString(). The format of the string returned by the toString methods is shown on the sample run below. Additionally, each of the sub-classes must override getBookType to return “Library Book” or “Bookstore Book.” This method may be used whenever you are in need to tell if a book is a bookstore or a library book. - Feel free to add private methods to any of the classes to avoid code redundancy. - The code should handle up to 100 books. For this, your code must use one array of type Book (not an ArrayList nor any built-in data structure class) in which you reference objects of both classes BookstoreBook and LibraryBook.
How would I create this using Java. Sample run attached in image.
The goal of this is to create two classes BookstoreBook and LibraryBook that both extend the class Book. The class Book is to be made abstract and to have these private attributes:
author: String
tiltle: String
isbn: String
To the Book class, add the abstract method: public String getBookType();
- The BookstoreBook has an additional data member to store the price of the book, and whether the book is on sale or not. If a bookstore book is on sale, we need to add the reduction percentage (like .2 off...etc). For that, add double price, boolean onSale and double saleRate as private fields to the BookstoreBook class. Obviously, saleRate is 0.0 when onSale is false.
- In the LibraryBook class, we add Subject and callNumber as String. The call number is automatically generated by the following procedure:
The callNumber has the format S.XX.YYY.C, where S is the subject code. The list of subject codes is provided at the end of this document, XX is the floor number that is randomly assigned (our library has 15 floors: 01, 02, ...15), YYY are the first three letters of the author’s name (we assume that all names are at least three letters long), and C is the last character of the isbn. For example, Q.09.JON.T is the call number for a Science book that is located on the 9th floor of the library and whose author’s name starts with JON. The isbn of that book ends with the character T.
- In each of the three classes mentioned above, add the setters, the getters, at least two constructors (of your choosing). Override the toString method in the class Book to return a string containing the isbn, author and the title. In the BookstoreBook and LibraryBook classes, override the toString to add the additional information to the returned string, using super.toString(). The format of the string returned by the toString methods is shown on the sample run below. Additionally, each of the sub-classes must override getBookType to return “Library Book” or
“Bookstore Book.” This method may be used whenever you are in need to tell if a book is a bookstore or a library book.
- Feel free to add private methods to any of the classes to avoid code redundancy.
- The code should handle up to 100 books. For this, your code must use one array of type Book (not an ArrayList nor any built-in data structure class) in which you reference objects of both classes BookstoreBook and LibraryBook.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images