Shopping Item (item)
Properties
Product Object (the PID of the product is also the primary key of the shopping item) product
Purchase quantity (user input) Count
Subtotal (Purchase quantity * Product Unit Price (product.getshop_price)) subtotal = Count*product.getprice ()
Cart (CART)
Properties
Map collection (product PID, shopping Item) map (String, item)
Total amount (sum of subtotals for all shopping items, initial value of 0) total=0.0
Action
Add shopping items to Cart
Delete a shopping item from your shopping cart
Empty shopping Cart
Add a shopping cart process
1. Create a shopping item item
2. Determine if the shopping cart has this item
Remove items in Item pid:pid = Item.getproduct (). Getpid ();
Use Map.containskey (PID) to determine if the item is already included in the shopping cart's map collection
2.1 Cart contains this item: Modify the purchase quantity in item and modify the total amount in the cart
Modified Purchase Quantity: Count = Item.setcount (Map.get (PID). GetCount () +item.getcount ());
Total value of the revised amount: Total = Total (original sum) + item.getsubtotal () (sum of new amounts);
2.2 Cart does not contain this item: Add (product PID, shopping item) directly to the map collection and calculate the total amount
Add Map:map.put directly (Item.getproduct (). Getpid (), item);
Total + = Total (Original amount) + Item.getsubtotal
Add Shopping cart over end
Remove a shopping item from your shopping cart
1. Delete the shopping item Cartitem item = Map.Remove (PID) according to the PID;
2. Modify the total amount in the shopping cart
Shopping Cart Current Amount total = Total Shopping cart amount-Subtotal of deleted item amount
Total value of shopping cart-= item.getsubtotal ();
The end of the process of deleting a product in a shopping cart
Empty shopping Cart
1. Use the Clear () method to empty the shopping cart item map.clear ();
2. Modify the cart amount to 0.0 total = 0.0
Shopping Cart Pseudocode (Java) in the mall system, welcome to communicate [email protected] )