Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are to write a set of supporting classes for a simple shopping program. We are providing GUI code ( Graphical User Interface ) that
You are to write a set of supporting classes for a simple shopping program. We are providing GUI code Graphical User Interface that will provide the front end to the program. You are to write the back end what is often referred to as the domain specific code
Below is a screen shot of what the program could look like when the user has selected various items to order.
ShoppingCart.png
Prices are expressed using doubles and quantities are expressed as simple integers eg you cant buy of something Notice that some of the items have a discount when you buy more. For example, silly putty normally costs $ each, but you can buy for $ These items have, in effect, two prices: a single item price and a bulk item price for a bulk quantity. When computing the price for such an item, apply as many of the bulk quantity as you can and then use the single item price for any leftovers. For example, the user is ordering buttons that cost $ each but can be bough t in bulk for $ The first are sold at that bulk price $ and the two extras are charged at the single item price $ each for a total of $
At the bottom of the frame you will find a checkbox for an overall discount. If this box is checked, the user is given a discount off the total price. This is computed using simple double arithmetic, computing a price that is of what it would be otherwise. For example, if we turn on that checkbox, the frame looks like this:
ShoppingCartWithDiscount.png
You are to implement four classes that are used to make this code work. You should implement a class called Item that will store information about the individual items. It should have the following public methods.
Class: Item
Method
Description
Itemname price
Constructor that takes a name and a price as arguments. The name will be a String and the price will be a double. Should throw an IllegalArgumentException if price is negative.
Itemname price, bulk quantity, bulk price
Constructor that takes a name and a singleitem price and a bulk quantity and a bulk price as arguments. The name will be a String and the quantity will be an integer and the prices will be doubles. Should throw an IllegalArgumentException if any number is negative.
priceForquantity
Returns the price for a given quantity of the item taking into account bulk price, if applicable Quantity will be an integer. Should throw an IllegalArgumentException if quantity is negative.
toString
Returns a String representation of this item: name followed by a comma and space followed by price. If this has a bulk price, then you should append an extra space and a parenthesized description of the bulk pricing that has the bulk quantity, the word for and the bulk price.
equals
You should make sure that you can compare items based on the contents of the item rather than by asking if two variables refer to the same Item object You can do this by overriding the equals method.
This is covered in section of the textbook starting with the section named "The equals Method" and finishing with the section named "The instanceOf keyword" There's also a bunch of examples of overriding equals in Java online, such as this one you might want to skip to the section entitled "Implementing Equals"
Make sure that you implement equals, and do so correctly as described in the textbook
Two items are the same if they have the same name and the same price.
You should implement a class called Catalog that stores information about a collection of these items. It should have the following public methods.
Class: Catalog
Method
Description
Catalogname
Constructor that takes the name of this catalog as a parameter. The name will be a String.
additem
Adds an Item at the end of this list.
size
Returns the number of items in this list.
getindex
Returns the Item with the given index based
getName
Returns the name of this catalog.
You should implement a class called ItemOrder that stores information about a particular item and the quantity ordered for that item. It should have the following public methods.
Class: ItemOrder
Method
Description
ItemOrderitem quantity
Constructor that creates an item order for the given item and given quantity. The quantity will be an integer.
getPrice
Returns the cost for this item order.
getItem
Returns a reference to the item in this order.
You should implement a class called ShoppingCart that stores information about the overall order. It should have the following public methods.
Class: ShoppingCart
Method
Description
ShoppingCart
Constructor that creates an empty list of item orders.
additem order
Adds an item order to the list, replacing any previous order for this item with the new order. The parameter will be of type ItemOrder.
setDiscountvalue
Sets whether or not this order gets a discount true means there is a discount, fals
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started