コード例 #1
0
 public List<CartItem> getPros() throws Exception {
   List<CartItem> items = new ArrayList<CartItem>();
   for (CartItem item : store) {
     if (item.isBuy()) {
       items.add(item);
     }
   }
   return items;
 }
コード例 #2
0
 // 计算商品总金额
 public double cost() throws Exception {
   double total = 0;
   for (CartItem item : store) {
     if (item.isBuy() == true) {
       total += item.getProduct().getDangPrice() * item.getQty();
     }
   }
   return total;
 }
コード例 #3
0
 /*
  *
  * 计算节省价钱
  */
 public double sale() throws Exception {
   double save = 0;
   for (CartItem item : store) {
     if (item.isBuy() == true) {
       save +=
           (item.getProduct().getFixedPrice() - item.getProduct().getDangPrice()) * item.getQty();
     }
   }
   return save;
 }
コード例 #4
0
  public String store() {
    StringBuffer sub = new StringBuffer();
    if (store.size() == 0) {
      sub.append("0"); // 导入时做判断
    } else {
      for (int i = 0; i < store.size(); i++) {
        CartItem item = store.get(i);
        sub.append(item.getProduct().getId() + "," + item.getQty() + "," + item.isBuy() + ";");
      }
    }
    // if(sub.length()>1){
    // sub.deleteCharAt(sub.length()-1);
    // }

    return sub.toString();
  }