shoppingcart.java
来自「采用struts+hibernet+javabean+jsp 些得shop购物网」· Java 代码 · 共 80 行
JAVA
80 行
package com.hnzt.bean;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class ShoppingCart{
private Map shopCart = new HashMap();
private double allGoodsPrice = 0;
public void addGoods (String username,String goodsId,String goodsName,double goodsPrice,int goodsAmount,String pnumber,String manu_u)
{
CartGoodsInf cartGoodsInf = (CartGoodsInf)shopCart.get(goodsId);
if(cartGoodsInf != null)
{
int amount = cartGoodsInf.getGoodsAmount();
amount = amount + goodsAmount;
cartGoodsInf.setGoodsAmount(amount);
}
else
{
cartGoodsInf = new CartGoodsInf(username,goodsId, goodsName, goodsPrice, goodsAmount,pnumber,manu_u);
shopCart.put(goodsId,cartGoodsInf);
}
}
public void deleteGoods(String goodsId)
{
CartGoodsInf cartGoodsInf = (CartGoodsInf)shopCart.get(goodsId);
if(cartGoodsInf != null)
{
shopCart.remove(goodsId);
}
}
public void changeAmount(String goodsId, int goodsAmount)
{
CartGoodsInf cartGoodsInf = (CartGoodsInf)shopCart.get(goodsId);
if(cartGoodsInf != null)
{
cartGoodsInf.setGoodsAmount(goodsAmount);
}
}
public Map getShopCart()
{
return this.shopCart;
}
public double getAllGoodsPrice()
{
this.allGoodsPrice = 0;
Iterator it = shopCart.keySet().iterator();
while(it.hasNext())
{
String goodsId = (String)it.next();
CartGoodsInf cartGoodsInf = (CartGoodsInf)shopCart.get(goodsId);
if(cartGoodsInf != null)
{
this.allGoodsPrice = this.allGoodsPrice+cartGoodsInf.getTotalPrice();
}
}
BigDecimal allGoods=new BigDecimal(this.allGoodsPrice);
allGoods=allGoods.setScale(2,5);
this.allGoodsPrice=allGoods.doubleValue();
return this.allGoodsPrice;
}
public void clearAllGoodsPrice()
{
this.allGoodsPrice = 0;
}
public void clearShoppingCart()
{
this.shopCart = new HashMap();
this.allGoodsPrice = 0;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?