📄 gouwuche.java
字号:
package cn.aiqinzhe;
import java.util.*;
import javax.transaction.Synchronization;
public class Gouwuche {
private HashMap<Integer,Sp> gwc = null; //购物车
private int zsl = 0;//总数量
public Gouwuche(){
gwc = new HashMap<Integer,Sp>();
}
//添加商品
public synchronized void addSp(Integer id, SpDX sp){
if(!gwc.containsKey(id)){
Sp temp = new Sp(sp);
gwc.put(id, temp);
zsl++;
}
}
//删除
public synchronized void delSp(Integer id) {
if(gwc.containsKey(id)){
gwc.remove(id);
zsl--;
}
}
//清空
public synchronized void qingkong() {
gwc.clear();
zsl = 0;
}
//取得总数量
public synchronized int getZsl(){
return zsl;
}
//设置商品数量
public synchronized void setSpSl(Integer id, int sl) {
if(gwc.containsKey(id)){
Sp temp = gwc.get(id);
if(sl <= 0){
gwc.remove(id);
}else {
temp.setSl(sl);
}
}
}
//取得总价格
public synchronized float getZjg(){
float i = 0.0f;
Iterator it = gwc.values().iterator();
while(it.hasNext()){
Sp temp = (Sp)it.next();
i += temp.getSpJg();
}
return i;
}
// 得到数目。
public synchronized Collection getSm()
{
return gwc.values();
}
//判断存在
public synchronized boolean ifYes(Integer id)
{
if(gwc.containsKey(id))
return true;
else
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -