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

📄 shoppingcart.java

📁 一个J2EE 做的 网上图书销售管理系统
💻 JAVA
字号:
package com.briup.bean;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public class ShoppingCart {
	private Map cart = new TreeMap();
	
	public void addLine(Orderline line) {
		Orderline orderLine = (Orderline)cart.get(line.getBook().getId());
		if(orderLine != null) 
			orderLine.setNum(orderLine.getNum()+line.getNum());
		else if(line.getNum()>0)
			cart.put(line.getBook().getId(), line);
	}
	
	public void dropLine(Integer lineid) {
		cart.remove(lineid);
	}
	
	public Orderline getOrderline(Integer lineid){
		return (Orderline)cart.get(lineid);
	}
	
	public Collection getOrderlines() {
		return cart.values();
	}
	
	public double getCost() {
		double cost = 0.0;		
		for(Iterator it = getOrderlines().iterator();it.hasNext();) {
			Orderline orderLine = (Orderline)it.next();
			cost += orderLine.getBook().getPrice() * orderLine.getNum();
			
		}
		return cost;
	}
	
	public void removeAll() {
		cart.clear();
	}
	
	public boolean isEmpty(){
		return cart.isEmpty();
	}
}

⌨️ 快捷键说明

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