急急急购物车问题如何实现购物物品自动曾家数量的问题 方法有很多啊,你是要设计思路啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是我做的一个给看看 private double total; //购物车总价 private HashMap items; //购物车商品 public CartDAO(){ total=0; items=new HashMap(); try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } } public double getTotal() { return total; } public Collection getItems() { return items.values(); } //增加商品 public void add(Cart vo){ //判断商品是否存在购物车中 if(items.containsKey(vo.getGoodsId())){ //存在该商品,数量增加 Cart cur=(Cart)items.get(vo.getGoodsId()); cur.setNumber(cur.getNumber()+1); }else{ // 不存在该商品,新增商品放入items中 vo.setNumber(1); items.put(vo.getGoodsId(),vo); } //改总价 total+= vo.getPrice()*1; } //删除商品 public void delete(Cart c){ if(items.containsKey(c.getGoodsId())){ Cart p=(Cart)items.get(c.getGoodsId()); double m=p.getPrice()*p.getNumber(); total=total-m; items.remove(c.getGoodsId()); } } //商品数量追加 public void update(Integer id,int number){ Cart cart=(Cart)items.get(id); cart.setNumber(number); items.put(id,cart); } //清空购物车 public void clear(){ items.clear(); total = 0; } //结算 /** * 物品总金额 * @return double */ public double reckoning(){ return total; } //商品种类 public int typecount(){ return items.size(); } /** * 所有商品数量 * @return double */ public int count(){ int num=0; Collection c=items.values(); Iterator i=c.iterator(); while(i.hasNext()){ Cart vo=(Cart)i.next(); num=num+vo.getNumber(); } return num; } 一个子类要调用父类的方法时,默认是使用this还是super? hibernate 映射 求教 页面返回值,ie可以 火狐却不行。(急啊!) 很奇怪的struts2配置问题 java是非题 DWR + Spring 问题 各位达人:struts1.2 DynaValidatorForm的bug!大家都过来看看! sql连接数据库问题,请指教 J2EE/J2SE/J2ME三者的区别在哪里?? 关于读文件然后写入数据库的效率问题 这种情况会不会排队执行--关于网络io的
private double total; //购物车总价
private HashMap items; //购物车商品 public CartDAO(){
total=0;
items=new HashMap();
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public double getTotal() {
return total;
} public Collection getItems() {
return items.values();
} //增加商品
public void add(Cart vo){
//判断商品是否存在购物车中
if(items.containsKey(vo.getGoodsId())){
//存在该商品,数量增加
Cart cur=(Cart)items.get(vo.getGoodsId());
cur.setNumber(cur.getNumber()+1); }else{
// 不存在该商品,新增商品放入items中
vo.setNumber(1);
items.put(vo.getGoodsId(),vo);
}
//改总价
total+= vo.getPrice()*1;
} //删除商品
public void delete(Cart c){
if(items.containsKey(c.getGoodsId())){
Cart p=(Cart)items.get(c.getGoodsId());
double m=p.getPrice()*p.getNumber();
total=total-m;
items.remove(c.getGoodsId());
}
}
//商品数量追加
public void update(Integer id,int number){
Cart cart=(Cart)items.get(id);
cart.setNumber(number);
items.put(id,cart);
} //清空购物车
public void clear(){
items.clear();
total = 0;
}
//结算 /**
* 物品总金额
* @return double
*/
public double reckoning(){
return total;
}
//商品种类
public int typecount(){
return items.size();
}
/**
* 所有商品数量
* @return double
*/
public int count(){
int num=0;
Collection c=items.values();
Iterator i=c.iterator();
while(i.hasNext()){
Cart vo=(Cart)i.next();
num=num+vo.getNumber();
}
return num;
}