First, demand analysis
Complete a single-machine version of the shopping Cart
(1) First set up a text file, define the product you want. By product number, commodity name, commodity brand, price as the content of the document, the intermediate requirements with a semicolon or split
(2) Write the program, define a commodity class, the contents of the file for all the properties of the class, when the program runs up, each record in the file, on the should class each instance, and load all the goods into memory.
(3) Display all goods to the graphical interface, provide 1. Purchase, 2. View, 3. Checkout (exit), 4. Delete, 5. Modify 5 methods, the customer can select by number.
(4) When you choose to purchase, you need to prompt the customer to enter the goods to be purchased, and add the purchased goods to the shopping cart (must support the purchase of the same product multiple times), after the purchase to show the customer has been placed in the shopping cart in the total price of all goods.
(5) Deletion and modification are based on items in the shopping cart, not on existing products.
(6) Checkout means exit and end of procedure.
Second, this group of topics and my task: Shopping cart tasks:
① read the product information from the file
② display all items on the graphical interface
③ offers 1. Purchase, 2. View, 3. Checkout (exit), 4. Delete, 5. Modify 5 methods
④ to add purchased items to the shopping cart
⑤ Delete and modify items in your shopping cart
⑥ Checkout calculates the total price of the item in the cart and exits
Iii. Overall Design (summary design)
① reads the product information from the file and loads it into memory, each message corresponds to an instance of a commodity good class, and is saved using a map
②jscrollpane loading jtable to showcase all products
③ Shopping cart products with ArrayList to store, buy goods call Add () method to join the ArrayList (in the case of a shopping cart without this item), delete that is ArrayList remove an element, modify the call Good Class Setnum () method to make a number of modifications
The display of the goods in the ④ shopping cart is also used to load the jtable in the JScrollPane
⑤ each interface has its own background image, set in the Layeredpane layer, the other containers are set transparent to make the background picture visible
Four, I am responsible for the main function display and code analysis of the main interface:
Code Analysis: New interface when clicking a button
Mall:
Code Analysis: According to the input product number of the corresponding key in the map of the commodity class good instance, if the shopping cart ArrayList does not have this good, then directly join, if already exist, only set his number for the original quantity plus the number of new inputs
Shopping Cart:
Code Analysis: Provides a way to calculate the total price of merchandise in a shopping cart, and responds when clicked on a button
Checkout:
Code Analysis: Call the Gettotalmoney () method to get the total price, exit the program using the System method exit ()
Modify:
Code Analysis: Traverse the ArrayList of the items in the shopping cart, find the good instance of the corresponding number and modify its Num property
Delete:
Code Analysis: Traverse the ArrayList of the merchandise in the shopping cart, find the corresponding number good class instance, call the Remove method to remove it from
IV. Testing and improvement testing: requirements can be fulfilled in the requirements
Improvement: Use the Try-catch block to handle code snippets that may throw exceptions, such as a pop-up message box to prompt the user and empty the text box if the number or number entered is not a number.
201621123063 "Java Course design Report"