Question: Implement a Java application, called BookstoreApplication, to be used in a retail book store. You will implement three classes: Book, Invoice, and Driver. Book class:
Implement a Java application, called BookstoreApplication, to be used in a retail book store. You will implement three classes: Book, Invoice, and Driver.
Book class:
This class represents a book item that is sold in the retail store. The book should be identified by three instance variables: title String weight double price double and discount double
Implement the following methods for the Book class:
A constructor to initialize all instance variables except discount which is set to zero.
Getters all instance variables.
A setter method for discount. Note that discount will be entered as a percentage, you have to convert to its decimal number equivalent before used in a calculation. eg should converted to
adjustPrice: a method than takes an amount of type double and adds that amount of money to the books price. Note that the amount can be positive or negative as a books price may be increased or decreased.
priceAfterDiscount: a method that calculates and returns the discounted books price after applying the discount. Note that this method should not change the value of the books price.
equals: a method to test the equality of two books. Two books are considered to be equal if they have the same title, the same price and the same weight.
toString: a method that returns a nicely formatted string description of the book.
Invoice class:
The Invoice class represents an invoice or a receipt. To keep the application simple, an invoice can contain at most three books. The Invoice class is identified by the following instance variables:
customer: a string that represents the customer's name.
books: an array type Book.
Implement the following methods for the Invoice class:
A constructor that takes as input only the customer's name and creates an invoice where the book is null.
getTotal: a method that calculates and returns the total cost of that invoice which is the sum of prices of all books in the invoice Note that null books should not be included in the total cost calculations.
getDiscountedTotal: a method that calculates and returns the total cost of that invoice which is the sum of prices after applying discount of all the books in the invoice Note that null books should not be included in the total cost calculations.
getTotalWeight: a method that calculates and returns the total weight of all books in this invoice.
addBook: a method that takes three input parameters to represent the books title, price and weight. The method then creates an object of type Book and assigns this object to one of the invoice's book array element. Note that the method should throw an exception if a book cannot be added if the invoice already has three books.
adjustPrice: a method that takes two input, namely bookNum and priceAdjustment, where bookNum is either or The method then adjusts the price of the given book. Note that the method should throw an exception if bookNum is invalid.
applyDiscount: similar to adjustPrice this method sets discount of one of the invoice's books. The method takes two inputs, namely bookNum and discount, where bookNum is either or The method then sets the specified books discount to the input discount value. The method should throw an exception if the input bookNum is invalid.
calculateTax: a static method that is used to calculate the amount of sales tax to be paid. The method takes two input parameters both of type double. The first input parameter, called cost, represents the total cost to be taxed, while the second parameter, called taxRate, represents the tax rate in percentage. The method then calculates and returns the amount of tax to be paid using the following formula:
tax cost taxRate
For example, if the cost is $ and taxRate is ie the amount of tax is which is $
toString: a method that returns a string representation of the invoice that includes the following:
o customer's name,
o details of the nonnull invoice's books,
o the total weight of all books in the invoice,
o the invoice's total before and after discount,
o the amount of tax to be paid where the tax is calculated based on the discounted invoice's total, and
o the overall cost which is equal to discounted total tax
Driver class:
Your Driver class should do the following actions:
creates two invoices with your choice of customer names.
Add three books to the first invoice and two books to the second invoice.
Apply discount to book # on both invoices.
Apply discount to book # on both invoices.
Adjust the price of book # in the second invoice by adding $
prints both invoices in a nicely formatted output use tax rate of
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
