⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cart.java

📁 演示简单Java语言基础
💻 JAVA
字号:
package wyf;
import java.util.*;

public class Cart
{
	HashMap hm=new HashMap();
	double total=0;
	public void add(String sid)
	{
		if(hm.containsKey(sid))
		{
			int xc=((Integer)hm.get(sid)).intValue()+1;
			hm.put(sid,new Integer(xc));;
		}
		else
		{
			hm.put(sid,new Integer(1));			
		}
		total=total+DBBean.getPrice(sid);		
	}
	
	public double getTotal()
	{
		return total;
	}
	
	public void setCount(int c,String sid)
	{
		int yc=((Integer)hm.get(sid)).intValue();
		total=total+(c-yc)*DBBean.getPrice(sid);
		hm.put(sid,new Integer(c));	
	}
	
	public void deleteFromCart(String sid)
	{
		int yc=((Integer)hm.get(sid)).intValue();
		total=total-yc*DBBean.getPrice(sid);
		hm.remove(sid);
	}
	
	public boolean isEmpty()
	{
		return hm.isEmpty();
	} 
	
	public String[][] getCart()
	{
		Set ks=hm.keySet();
		Iterator ii=ks.iterator();
		int size=hm.size();
		String rs[][]=new String[size][];
		for(int i=0;i<size;i++)
		{
			String sid=(String)ii.next();
			String[] sa=new String[4];
			sa[0]=sid;
			String[] sat=DBBean.getDetail(sid);
			sa[1]=sat[0];
			sa[2]=sat[1];
			sa[3]=((Integer)hm.get(sid)).toString();
			rs[i]=sa;
		}
		return rs;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -