shopcart.java
来自「网上购物系统的简易代码」· Java 代码 · 共 38 行
JAVA
38 行
package com.tarena.develop.service.impl;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import com.tarena.develop.entity.OrderLine;
import com.tarena.develop.entity.Product;
public class ShopCart {
private Set<OrderLine> orderlines=new HashSet<OrderLine>();
private Double cost;
public void addProduct(Product product){
// int pid=product.getPid();
//OrderLine orderline=new OrderLine();
Boolean flag=false;
Iterator<OrderLine> it=orderlines.iterator();
while(it.hasNext()){
OrderLine ol=it.next();
if(ol.getProduct().getPid()==product.getPid()){
ol.setAmount(ol.getAmount()+1);
flag=true;
cost+=product.getPrice();
return;
}
}
if(flag){
OrderLine orderline=new OrderLine();
orderline.setProduct(product);
orderline.setAmount(1);
orderlines.add(orderline);
cost+=product.getPrice();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?