Shopping Cart Pseudocode (Java) in mall system (beginner, Welcome to communication andy_zhou.china@outlook.com)

Source: Internet
Author: User



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] )


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.