Question: Problem Description to implement a Java application, called ShoppingApplication, that can be used in a retail store. You are asked to implement three classes: Item,
Problem Description
to implement a Java application, called
ShoppingApplication, that can be used in a retail store. You are asked to implement
three classes: Item, Invoice, and InvoiceDriver. Each of these classes is
described below.
Item class
The Item class represents of an item that is being sold in the retail store (e.g., book or pencil)
where an item is identified by three instance variables: name (of type Sring), weight (of
type double), price (of type double), and currentDiscount (of type int).
Implement the following methods for the Item class:
A constructor to initialize all instance variables except currentDiscount which is set
to zero.
Getters all instance variables.
A setter method for currentDiscount. Note that currentDiscount is an
integer value. For example, if currentDiscount is 10, then this means that the item's
price is reduced by 10%.
adjustPrice: a method than takes an amount (of type double) and adds that
amount of money to the item's price. Note that the amount can be positive or negative
as an item's price may be increased or decreased.
priceAfterDiscount: a method that calculates and returns the discounted item's
price after applying the current discount. Note that this method does not change the
value of the item's price.
equals: a method to test the equality of two items. Two items are considered to be
equal if they have the same price and the same weight.
toString: a method that returns a nicely formatted string description of the item.
Invoice class:
The Invoice class represents an invoice or a receipt. In this simplistic application, an invoice
can have at most three items. Basically, the Invoice classis identified by the following instance
variables:
customer: a string that represents the customer's name.
item1: an instance variable of type Item.
item2: an instance variable of type Item.
Item3: an instance variable of type Item.
Implement the following methods for the Invoice class:
A constructor that takes as input only the customer's name and creates an invoice were
the three items are null.
getTotal: a method that calculates and returns the total cost of that invoice (which is
the sum of prices of the all items in the invoice). Note that null items are not 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 the all items in the invoice).
Note that null items are not included in the total cost calculations.
getTotalWeight: a method that calculates and returns the total weight of all items
in this invoice.
addItem: a method that takes three inputs parameters to represent the item's name,
price and weight. The method then creates an object of type Item and assigns this
object to one of the invoice's items. Note that item1 must be filled before item2 and
item2 must be filled before item3. The method should also print an error message to
say that the item cannot be added if the invoice already has three items.
adjustPrice: a method that takes two input, namely itemNum and
priceAdjustment, where itemNum is either 1, 2 or 3. The method then adjusts the
price of the given item number. The method should display an error message if the input
itemNum is invalid.
applyDiscount: similar to adjustPrice, this method sets currentDiscount
of one of the invoice's items. The method takes two inputs, namely itemNum and
discount, where itemNum is either 1, 2 or 3. The method then sets the specified
item's discount to the input discount value. The method should display an error
message if the input itemNum 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 current tax rate in percent. The method then
calculates and returns the amount of tax to be paid using the following formula:
tax = (cost * taxRate)/100.
For example, if the cost is $60 and taxRate is 7.5 (i.e., 7.5%), the amount of tax is
(60*7.5)/100 while is $4.5.
toString: a method that returns a string representation of the invoice that includes
the following:
o customer's name,
o details of the non-null invoice's items,
o the total weight of all items 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 .
InvoiceDriver class:
Your driver class should do the following actions:
creates two invoices with your choice of customer names.
Add three items to the first invoice and two items to the second invoice.
Apply 10% discount to item1 in both invoices.
Apply 20% discount to item2 in both invoices.
Adjust the price of item3 in the second invoice by adding $2.
prints both invoices in a nicely formatted output (use tax rate of 4.5%)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
