当前位置:酷百书>百科知识>购物车的Java代码

购物车的Java代码

2023-11-07 06:08:37 编辑:join 浏览量:584

购物车的Java代码

购物车的Java代码

import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;public class ShoppingCartManager { HashMap hm=new HashMap(); float totlePrice=0; //添加book到购物车 public void addBook(String bookId,String bookQuantity){ if(hm.containsKey(bookId)){ int value=Integer.parseInt(hm.get(bookId)); value+=Integer.parseInt(bookQuantity); hm.put(bookId, value+""); }else{ hm.put(bookId, bookQuantity); } } //修改数量 public void updateQuantity(String bookId,String bookQuantity){ hm.put(bookId, bookQuantity); } /誉高/获取购物车的所有信息 并计算总价 public ArrayList getShoppingCart(){ ArrayList al=new ArrayList(); Iterator i=hm.keySet().iterator(); String ids=""; BookTableManager btm=new BookTableManager(); while(i.hasNext()){ ids=ids+","+i.next(); } al= btm.selectByBookIds(ids); totlePrice=0; //清空总价,防答虚启止无清如限累计 for(int j=0;j

标签:购物车,Java,代码

版权声明:文章由 酷百书 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.kubaishu.com/article/384224.html
热门文章