📄 cart.java
字号:
/* * Cart.java * * Created on 2006年9月14日, 下午2:11 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package com.shopping.model;import java.util.*;/** * * @author 曹昊 */public class Cart { private Map<String,Item> items = new HashMap<String,Item>(); private double cost = 0.0;//总价格 public Cart(){} public void addItem(Item item){ items.put(item.getProduct().getId()+"",item); } public void modifyNumberByProductId(String productId, int number){ Item item = (Item)items.get(productId); item.setNumber(number); item.incrementCost(); } public void deleteItemByProductId(String productId){ items.remove(productId); } public void deleteItemsByProductId(String[] productId){ for(int i = 0; i< productId.length; i++){ items.remove(productId[i]); } } public double getCost(){ cost = 0.0; Iterator it = items.values().iterator(); while(it.hasNext()){ Item item = (Item)it.next(); cost += item.getCost(); } return cost; } public void setCost(double cost){ this.cost = cost; } public void clear(){ if(items != null){ items.clear(); } setCost(0.0); } public Map<String,Item> getItems(){ return this.items; } public boolean isEmpty(){ return items.size() == 0; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -