Question: Please make these 3 classes in java The class should implement an invoice containing zero or more lines * of products with their prices and
Please make these classes in java
The class should implement an invoice containing zero or more lines
of products with their prices and quantities, eg
Oatmeal Cookies, price quantity
you may also think of it in terms of a "Shopping cart" to some extent the two are similar
ONE public constructor should exist no other constructors are permitted:
Invoice: creates an empty invoice, so that the items can be added to it
In addition to the above, the following public methods should be implemented:
public void addItemProduct item, int quantity adds the new line to the invoice
NOTE: for simplicity, if the same items are added multiple times, they should remain on
separate lines ie identical products should NOT be merged into one line
public List getItems returns a list of all the invoice items,
with the items in the same order that they were added in using the addItem method above
IMPORTANT
The client calling getItems should not be able to change the invoice items
public double getTotal returns the total cost of the items on the invoice
String toString
this one should return a String in the following form:
Invoice
Chocolate Cake, price quantity
Oatmeal Cookies, price quantity
Tasty Chocolates, price quantity
Total:
Of course, the numbers above may be very different for any particular instance
The class should implement an item describing a line on an invoice:
a product including its name and price and the quantity, as an integer
The quantity above can be any integer eg negative values indicate a product
return for a refund
The class is intended to be used in the implementation of another class or classes
ONE public constructor should exist:
InvoiceItemProduct product, int quantity: creates an invoice line item with
the specified product and quantity
you may add other nonpublic constructors, if you desire
IMPORTANT
The product price may change after it's added to the invoice; however the price on the invoice
should not be affected eg if product that sells for $ is added to the invoice,
and then its price goes up to $ the price of the items already added should remain $
However, if more items are added they will use the new price of $
In addition, the following public methods should be implemented:
public Product getProduct
public int getQuantity
public void setQuantityint quantity
String toString
this one should return a String in the form of "name, priceX quantityY
where X is the item price, with two decimal digits; and Y is the quantity
The class should implement a product that could be sold in a store
The class is intended to be used in the implementation of another class or classes
ONE public constructor should exist:
ProductString name, double price: creates a product with the specified name and price
you may add other nonpublic constructors, if you desire
in addition to the above, the following public methods should be implemented:
public String getName
public double getPrice
public void setPricedouble price
String toString
this one should return a String in the form of "name, priceX where X is the item price, with two decimal digits no quotation marks
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
