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 3 classes in java
The class should implement an invoice containing zero or more lines
* of products with their prices and quantities, e.g.,
* Oatmeal Cookies, price=1.99, quantity=3
*(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 addItem(Product 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 (i.e., 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=21.99, quantity=1
* Oatmeal Cookies, price=1.99, quantity=3
* Tasty Chocolates, price=0.98, quantity=30
* Total: 57.36
*
* 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 (e.g., 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:
* InvoiceItem(Product product, int quantity): creates an invoice line item with
* the specified product and quantity
*(you may add other - non-public - 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 (e.g., if product that sells for $2.00 is added to the invoice,
* and then its price goes up to $2.50, the price of the items already added should remain $2.00.
* However, if more items are added they will use the new price of $2.50
*
* In addition, the following public methods should be implemented:
* public Product getProduct()
* public int getQuantity()
* public void setQuantity(int quantity)
*
* String toString()
* this one should return a String in the form of "name, price=X, quantity=Y"
* 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:
* Product(String name, double price): creates a product with the specified name and price
*(you may add other - non-public - constructors, if you desire)
*
* in addition to the above, the following public methods should be implemented:
* public String getName()
* public double getPrice()
* public void setPrice(double price)
*
* String toString()
* this one should return a String in the form of "name, price=X" 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!