Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Overview: You will be implementing a shopping cart final project that simulates

ID: 3622396 • Letter: O

Question

Overview:
You will be implementing a shopping cart final project that simulates a simplified web shopping cart program but runs from the command console window with menus.
Your program will read a file with data about products for sale (the inventory file).
It will display those products to the user and allow them to select and then add products to their ‘shopping cart’.
When the user chooses place order, the total order will be printed on the consol and output to a order file.
Features and grading:
Your final program will be graded on whether it has all the required features as well as good code design and style.
Here is a general break down of features:
1. External Product File
The program read in a list of available products for sale from an external file. Note that this file will not contain more than 50 products.
Each product in this file will have an id number (like A101, B26), a descriptive name, and a list price. This file is provided below.
2. When your program starts it will run from the console and will present a list of all the products and then the main menu. This main menu will have the following choices:

-------MAIN MENU- SHOP-------
1 - add product to shopping cart
2 - show shopping cart
4 - exit program
input your choice?

Your program will have one other major menu that can be displayed from choice 2:
The Shopping Cart Menu: (the items in the shopping cart will always be listed just prior to the menu being displayed)

-------CART MENU: -------
1 - place order
2 - cancel order
3 - main menu
input your choice?
Below is a detailed description of what each menu item does:

-------MAIN MENU-------
Note that before the main menu displays, the program will always list the current list of products.

1 - add product to shopping cart
Ask user for a product ID and the quantity they want to buy. Add this quantity and ID to the shopping cart list. If it is already in the shopping cart list, just replace the quantity amount.
2 - show shopping cart
Display the list of items in the shopping cart and then display the shopping cart menu.
3 - exit program
Display a goodbye message and exit program


-------CART MENU-------
Note that the list of all items in the cart will be displayed ever time the menu is displayed. This list will include a total column calculated from multiplying the quantity by the list price. After the items, will be a line with the grand total cost of the order.
1 - place order
Ask the user for his name, address, city, state, and zip information. Output this information and a list of the items on the cart to a order.txt file. Then reset the cart to empty go back to the main menu.
2 - cancel order
Remove all items form the cart then go back to the main menu
3 – main menu
go back to the main shopping menu


Implementation suggestion: ( in pseudo code )
Use separate static arrays for the product codes, descriptions, prices and quantities, and a static variable to hold the count of how many products are in the inventory. That way you will not need to pass arrays as parameters. Use the quantities array to hold the quantity for each product in the order and zero for any products that have not been added to the cart.

Create static methods for the following:
main
read products file into static arrays that are declared as class variables
call main method
display goodby message

main menu
loop:
display all products
display main menu
get user choice
if 1 then call add product to cart
if 2 then call cart menu
if 3 then break out of loop

cart menu
display current order or ‘cart empty’ if there are no orders
display cart menu
if 1 call write order
if 2 reset order
if 3 just return

read inventory
open and read inventory file into arrays

write order
ask user for address info
open and write order file, and output to console
reset the cart

add product to cart
get product code from user
find product code
get quantity from user
set the quantity in the quantity array



You can keep track of the current order by having a parallel array to the products that just keeps a quantity for each product or 0 if it is not on the order.
REMEMBER: you need to issue a extra nextLine() before you use nextLine() to read in some data like the product name, the address from user, etc.
This is because an previous nextInt, nextDouble, or next call left the input pointer just before the input of the enter key ( ). so by doing nextLine(), it will skip to the beginning of the current line. the second nextLine() will read in the whole line typed.


inventory.txt (each piece of data is on a new line: code, description, price):
A101
8 oz Can Green Peas
0.25
A201
4 Pack of Red Bell Pepper
1.75
B201
1 lb. Jack Cheese
2.23
Z101
Generic Kitchen scissors 8"
3.45
A102
Bag: 1 lb pinto beans
0.75
C211
12 Pk Zappo Dog food
17.00
C220
Furinator cat brush
32.95

Here is a Sample run:

java -jar store.jar

-------INVENTORY:-------
code description price each
A101 8 oz Can Green Peas 0.25
A201 4 Pack of Red Bell Pepper 1.75
B201 1 lb. Jack Cheese 2.23
Z101 Generic Kitchen scissors 8" 3.45
A102 Bag: 1 lb pinto beans 0.75
C211 12 Pk Zappo Dog food 17.00
C220 Furinator cat brush 32.95


-------MAIN MENU: SHOP-------
1 - add product to shopping cart
2 - show shopping cart
3 - exit program
input your choice? 1
input the product code to buy? c220
input the quanity to by (1 to 100, 0 to cancel)? 20

-------INVENTORY:-------
code description price each
A101 8 oz Can Green Peas 0.25
A201 4 Pack of Red Bell Pepper 1.75
B201 1 lb. Jack Cheese 2.23
Z101 Generic Kitchen scissors 8" 3.45
A102 Bag: 1 lb pinto beans 0.75
C211 12 Pk Zappo Dog food 17.00
C220 Furinator cat brush 32.95


-------MAIN MENU: SHOP-------
1 - add product to shopping cart
2 - show shopping cart
3 - exit program
input your choice? 1
input the product code to buy? b201
input the quanity to by (1 to 100, 0 to cancel)? 5

-------INVENTORY:-------
code description price each
A101 8 oz Can Green Peas 0.25
A201 4 Pack of Red Bell Pepper 1.75
B201 1 lb. Jack Cheese 2.23
Z101 Generic Kitchen scissors 8" 3.45
A102 Bag: 1 lb pinto beans 0.75
C211 12 Pk Zappo Dog food 17.00
C220 Furinator cat brush 32.95


-------MAIN MENU: SHOP-------
1 - add product to shopping cart
2 - show shopping cart
3 - exit program
input your choice? 2

-------CART CONTENTS:-------
qty code description price each line total
5 B201 1 lb. Jack Cheese 2.23 11.15
20 C220 Furinator cat brush 32.95 659.00
---------
TOTAL 670.15


-------CART MENU: -------
1 - place order
2 - cancel order
3 - main menu
input your choice? 1


place order
please enter your full name (to put on address) ?
please enter the first line of your address ?
please enter the city name ?
please enter the two letter state abbreviation ?
please enter the zip code ?

Your order is summarized here:
Ship To:
(address goes here)


-------CART CONTENTS:-------
qty code description price each line total
5 B201 1 lb. Jack Cheese 2.23 11.15
20 C220 Furinator cat brush 32.95 659.00
---------
TOTAL 670.15

-------INVENTORY:-------
code description price each
A101 8 oz Can Green Peas 0.25
A201 4 Pack of Red Bell Pepper 1.75
B201 1 lb. Jack Cheese 2.23
Z101 Generic Kitchen scissors 8" 3.45
A102 Bag: 1 lb pinto beans 0.75
C211 12 Pk Zappo Dog food 17.00
C220 Furinator cat brush 32.95


-------MAIN MENU: SHOP-------
1 - add product to shopping cart
2 - show shopping cart
3 - exit program
input your choice? 3


Thank you for shopping at our store


order.txt after above ran:
------------------------------------
(address in this area)

qty code description price each line total
5 B201 1 lb. Jack Cheese 2.23 11.15
20 C220 Furinator cat brush 32.95 659.00
---------



Explanation / Answer

Create a class for the shoping cart with functions add and show. Have a class for product with members like product, item no, cost, qty etc. Create an array of products in add function. Display contents in show function. Have a class to popluate product catalog from file. This can be done using Scanner class in java.util.Scanner or using FileInputStream in java.io along with StringTokenizer in java.util Have a separate class for product catalog and this should be used to check if item is present using a loop and for required quantity. To cancel an item search from the product object and remove it. To place output in file use FileOutputStream in java.io with functions such as writeBytes to write string and writeInt for integers.