The goal of this coding exercise 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. Your 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. The sample run below should give you a clear idea about how to code everything! Sample Run Welcome to the book program! Would you like to create a book object? (yes/no): yEs (yEs, Yes,..., No, NO,nO...etc all acceptable entries) Enter the author, title and the isbn of the book separated by /: Ericka Jones/Java made Easy/458792132 Got it! Now, tell me if it is a bookstore book or a library book (enter BB for bookstore book or LB for library book): BSB (Lb, bB...etc all acceptable entries) Oops! That's not a valid entry. Please try again: Bookstore Oops! That's not a valid entry. Please try again: bB Got it! Enter the list price of JAVA MADE EASY by ERICKA JONES: 14.99 Is it on sale? (yes/no): yes (yEs, Yes,..., No, NO,nO...etc all acceptable entries) Deduction percentage: 15% (Enter this as a percentage) Got it! Here is your bookstore book information [458792132-JAVA MADE EASY by ERICKA JONES- $14.99 listed for $12.74] (this output is what the toString() returns) If Java Made Easy wasn't on sale, your code should print: [458792132-JAVA MADE EASY by ERICKA JONES, $14.99] Would you like to create a book object? (yes/no): yeah Oops! That's not a valid entry. Please try again: yes Enter the author, title and the isbn of the book separated by /: Eryc Jones/Java as a healing language/95879213m Got it! Now, tell me if it is a bookstore book or a library book (enter BB for bookstore book or LB for library book): LB
The goal of this coding exercise 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. Your 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. The sample run below should give you a clear idea about how to code everything! Sample Run Welcome to the book program! Would you like to create a book object? (yes/no): yEs (yEs, Yes,..., No, NO,nO...etc all acceptable entries) Enter the author, title and the isbn of the book separated by /: Ericka Jones/Java made Easy/458792132 Got it! Now, tell me if it is a bookstore book or a library book (enter BB for bookstore book or LB for library book): BSB (Lb, bB...etc all acceptable entries) Oops! That's not a valid entry. Please try again: Bookstore Oops! That's not a valid entry. Please try again: bB Got it! Enter the list price of JAVA MADE EASY by ERICKA JONES: 14.99 Is it on sale? (yes/no): yes (yEs, Yes,..., No, NO,nO...etc all acceptable entries) Deduction percentage: 15% (Enter this as a percentage) Got it! Here is your bookstore book information [458792132-JAVA MADE EASY by ERICKA JONES- $14.99 listed for $12.74] (this output is what the toString() returns) If Java Made Easy wasn't on sale, your code should print: [458792132-JAVA MADE EASY by ERICKA JONES, $14.99] Would you like to create a book object? (yes/no): yeah Oops! That's not a valid entry. Please try again: yes Enter the author, title and the isbn of the book separated by /: Eryc Jones/Java as a healing language/95879213m Got it! Now, tell me if it is a bookstore book or a library book (enter BB for bookstore book or LB for library book): LB
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2PE
Related questions
Question
PLEASE WRITE THE CODE WITH USER ERROR AND ALL ACCEPTABLE ENTRIES!!!
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 7 steps with 11 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,