Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Working with Arrays Shopping Cart

pol212
pol212 


Project description in the word doc. Attachments Tags Clarifications

Answers

Java - Shopping Cart - Solution

dickersonka
dickersonka 



Attached is the solution to the Java - Shopping Cart assignment including source and comments. Attachments
Shopping.zip (1 K) Download
Preview
product = ""; quantity = 0; price = 0.0; } //constructor with parameters public CartItem(String inProduct, int inQuant, double inPrice) { product = new String(inProduct); quantity = inQuant; price = inPrice; } //getter setter public methods for each instance data public boolean

Preview
args) { ArrayList<CartItem> shoppingCart = new ArrayList<CartItem>(); Scanner scan = new Scanner(System.in); boolean keepGoing = true; while(keepGoing) { System.out.println("\nMenu - Managing a List"); System.out.println("1 - add an item to your cart"); System.out.println("2 - remove an item from your cart"); System.out.println("3 - view the items in your cart"); System.out.println("4 -

Screenshots
Purchase Answer

Answer

mariobeka
mariobeka 



Wrong submission. See below for the right one. Attachments
Shopping.java (4 K) Download Preview
item from the list"); System.out.println("3 view the items in the list"); System.out.println("4 end shopping and go to checkout"); System.out.println("5 Empty your cart"); System.out.println("6 Exit the program"); System.out.println("Select a menu option"); choice = scan.nextInt(); if (choice < 1 || choice > 6) { System.out.println("Enter a value between 1 and 6:"); }

CartItem.java (1 K) Download Preview
quantity; } public double getPrice() { return price; } public boolean equals(CartItem item) { //write the code for the equals method return this.product.equals(item.product); } public String toString() { //write code for toString method String

Shopping.java (4 K) Download Preview
the CartItem class to represent items in * your shopping cart. * In this driver program you will do the following: * Create the shopping cart object * Offer a menu of options: * 1 add an item to your cart * 2 remove an item from your cart *

CartItem.java (1 K) Download Preview
return price; } public boolean equals(CartItem item) { //write the code for the equals method return this.product.equals(item.product); } public String toString() { //write code for toString method NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(); String string =

TestResult.txt (2 K) Download Preview
an item to the list 2 remove an item from the list 3 view the items in the list 4 end shopping and go to checkout 5 Empty your cart 6 Exit the program Select a menu option 1 Add Item: Enter product name: T-Shirt Enter quantity: 1 Enter price: 10 New item was added to your Shopping Cart. Menu - Managing a

Screenshots
Purchase Answer

Answer

mariobeka
mariobeka 



This is the wright one. Here you'll find the modified Shopping.java & CartItem.java files as described in the doc file.
The result will be this one:
Menu - Managing a List
1 add an item to the list
2 remove an item from the list
3 view the items in the list
4 end shopping and go to checkout
5 Empty your cart
6 Exit the program
Select a menu option
1
Add Item:
Enter product name: T-Shirt

Enter quantity: 1

Enter price: 10
New item was added to your Shopping Cart.

Menu - Managing a List
1 add an item to the list
2 remove an item from the list
3 view the items in the list
4 end shopping and go to checkout
5 Empty your cart
6 Exit the program
Select a menu option
1
Add Item:
Enter product name: Shoes

Enter quantity: 1

Enter price: 30
New item was added to your Shopping Cart.

Menu - Managing a List
1 add an item to the list
2 remove an item from the list
3 view the items in the list
4 end shopping and go to checkout
5 Empty your cart
6 Exit the program
Select a menu option
1
Add Item:
Enter product name: Pants

Enter quantity: 2

Enter price: 15
New item was added to your Shopping Cart.

Menu - Managing a List
1 add an item to the list
2 remove an item from the list
3 view the items in the list
4 end shopping and go to checkout
5 Empty your cart
6 Exit the program
Select a menu option
3
--------Your Shopping Cart---------
Product Quantity Price

T-Shirt 1 $10.00
Shoes 1 $30.00
Pants 2 $15.00
-----------------------------------

Menu - Managing a List
1 add an item to the list
2 remove an item from the list
3 view the items in the list
4 end shopping and go to checkout
5 Empty your cart
6 Exit the program
Select a menu option
2
Enter product name: Pants
Item T-Shirt was not found in the list.
Item Shoes was not found in the list.
Item Pants has been removed.

Menu - Managing a List
1 add an item to the list
2 remove an item from the list
3 view the items in the list
4 end shopping and go to checkout
5 Empty your cart
6 Exit the program
Select a menu option
3
--------Your Shopping Cart---------
Product Quantity Price

T-Shirt 1 $10.00
Shoes 1 $30.00
-----------------------------------

Menu - Managing a List
1 add an item to the list
2 remove an item from the list
3 view the items in the list
4 end shopping and go to checkout
5 Empty your cart
6 Exit the program
Select a menu option
1
Add Item:
Enter product name: Pants

Enter quantity: 3

Enter price: 15
New item was added to your Shopping Cart.

Menu - Managing a List
1 add an item to the list
2 remove an item from the list
3 view the items in the list
4 end shopping and go to checkout
5 Empty your cart
6 Exit the program
Select a menu option
4
Your Total Price to pay is $85.00
Goodbye
Attachments
TestResult.txt (2 K) Download Preview
list 2 remove an item from the list 3 view the items in the list 4 end shopping and go to checkout 5 Empty your cart 6 Exit the program Select a menu option 3 --------Your Shopping Cart--------- Product Quantity Price T-Shirt 1 $10.00 Shoes 1 $30.00 ----------------------------------- Menu - Managing a List 1 add an item to the list 2

Shopping.java (4 K) Download Preview
scan = new Scanner(System.in); ArrayList<CartItem> shoppingCart = new ArrayList<CartItem>(); boolean keepGoing = true; String product; int quantity; double price; int choice = 0; double total = 0; CartItem item; while (keepGoing) { System.out.println("\nMenu - Managing a List"); System.out.println("1 add an item to the list"); System.out.println("2 remove an item from the

CartItem.java (1 K) Download Preview
java.util.Formatter; public class CartItem { private String product; private int quantity; private double price; //constructor public CartItem() { product = ""; quantity = 0; price = 0.0; } //constructor with parameters public CartItem(String inProduct,

Screenshots
Purchase Answer