Question: Write a java program with comments using the follwoing insructions: Design and code a class called InvoiceItem to store information about items purchased at a
Write a java program with comments using the follwoing insructions:
Design and code a class called InvoiceItem to store information about items purchased at a store. The following attributes are private instance variables:
Part description (String)
Item price (int)
Quantity purchased (int)
The class must include the following public methods:
method description
default constructor Sets description to none, item and quantity to 0.
Parameterized constructor Sets all three instance variables to data that is passed to it
setDescription Recieves a value to assign to private instance variable
setQuantity Recieves a value to assign to private instance variable. If it is not positive, set it to 0.
setPrice Recieves a value to assign to private instance variable. If it is not positive, set it to 0.
getDescription Returns private instance variable getQuantity Returns private instance variable
getPrice Returns private instance variable (inches)
getItemTotal Calculates and returns the amount for this item (quantity * price)
You are going to use this class in an app to process orders for a shop that sells weapons, shields, armor, potions for gaming characters.
Create parallel arrays in main to represent the products and prices of the items in an equipment shop. You will initialize the products and prices to the data listed in the sample output below.
Create an ArrayList of InvoiceItem objects to represent the items on customers order (their cart). As items are selected, objects with the appropriate data are added to this arraylist. A customer can purchase any number of items.
Create the following methods:
showProducts Receives the two arrays with products and prices, prints the menu of available items. Label the first item (in element 0) as 1, the second (in element 1) as 2, etc. (this does not need to be an additional array)
printInvoice Receives the arraylist which has the items ordered by the customer. Prints the invoice as shown in sample output.
Program operation:
Call showProducts to print the menu of available items and prices.
Then loop to allow customer to place select a product or enter 0 to end the order. Validate the users choice with a loop. (Note that item 1 is stored in element 0 of the array, item 2 is stored in element 1 of the array, and so on make any necessary adjustments in your code to address this.)
Display the item and price, ask for quantity (VALIDATE).
Add to the arraylist
Display total for this item
When order is done, call printInvoice to print the customer invoice
SAMPLE OUTPUT: (User input in bold)
Stuff R Us: Items in stock
1 - common sword 50
2 - jumping potion 85
3 - chain shirt 115
4 - breastplate 230
5 - steel shield 100
6 - wooden shield 250
Enter your choice or 0 to quit: 8
Invalid choice, re-enter: 5
steel shield , price is 100
How many to purchase? 0
Quantity must be greater than 0, re-enter: 3
Cost is $300
Enter your choice or 0 to quit: 1
common sword , price is 50
How many to purchase? 2
Cost is $100
Enter your choice or 0 to quit: 0
INVOICE
Qty Desc Price Item Total
3 steel shield $100 $300
2 common sword $50 $100
Total Due $400
Thank you for shopping with Stuff R Us
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
