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

📄 shopservice.java

📁 购物车,struts+jdbc 数据库sqlserver2
💻 JAVA
字号:
package org.y2t12.service;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

import org.y2t12.beans.ShopBean;

public class ShopService {

	private HashMap map = new HashMap();

	/**
	 * 判断购物车中是否存在要添加的书
	 * 
	 * @param 要添加的书
	 * @return 包含返回false不包含返回true
	 */
	public boolean isExist(ShopBean bean) {
		boolean flag = false;
		//判断是否包含此键
		if(!this.map.containsKey(new Integer(bean.getId()))){
			flag = true;
		}
		return flag;
	}

	/**
	 * 向购物车中添加书
	 * 
	 * @param bean
	 */
	public void addShopCart(ShopBean bean) {
		System.out.println(bean.getId());
		this.map.put(new Integer(bean.getId()), bean);
	}

	/**
	 * 返回购物车中所有的书
	 * 
	 * @return
	 */
	public Collection getAll() {
		return this.map.values();
	}
	/**
	 * 删除购物车中的书
	 * @param bookID
	 */
	public void removeBook(Integer bookID){
		this.map.remove(bookID);
	}
	
	public double getTotal(){
		double total = 0.0;
		Collection coll = this.getAll();
		Iterator it = coll.iterator();
		
		while(it.hasNext()){
			ShopBean bean = (ShopBean) it.next();
			total += bean.getPrice() * bean.getCount();
		}
		
		return total;
	}
}

⌨️ 快捷键说明

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