示例#1
0
 /**
  * TODO 修改购物车里食物的数量(可选).
  *
  * @see com.yummy.service.ICartManager#update(int, int)
  */
 public void update(int id, int quantities) {
   // TODO Auto-generated method stub
   for (int i = 0; i < items.size(); i++) {
     ItemDTO temp = items.get(i);
     if (temp.getId() == id) {
       temp.setOrderCount(quantities);
     }
   }
 }
示例#2
0
 /**
  * TODO 增加数量,用户重复点击放入购物车时调用。(可选).
  *
  * @see com.yummy.service.ICartManager#increase(int, int)
  */
 public void increase(int id, int quantities) {
   // TODO Auto-generated method stub
   for (int i = 0; i < items.size(); i++) {
     if (items.get(i).getId() == id) {
       ItemDTO temp = items.get(i);
       temp.setOrderCount(temp.getOrderCount() + quantities);
       break;
     }
   }
 }
示例#3
0
 /**
  * TODO 判断购物车是否已有相同食物存在(可选).
  *
  * @see com.yummy.service.ICartManager#isItemExist(int)
  */
 public boolean isItemExist(int id) {
   // TODO Auto-generated method stub
   boolean flag = false;
   for (int i = 0; i < items.size(); i++) {
     ItemDTO temp = items.get(i);
     if (temp.getId() == id) {
       flag = true;
     }
   }
   return flag;
 }
示例#4
0
 /**
  * TODO 删除购物车里面的食物(可选).
  *
  * @see com.yummy.service.ICartManager#delete(int)
  */
 public void delete(int id) {
   // TODO Auto-generated method stub
   Iterator iterator = items.iterator();
   while (iterator.hasNext()) {
     ItemDTO temp = (ItemDTO) iterator.next();
     if (temp.getId() == id) {
       items.remove(temp);
       break;
     }
   }
 }
示例#5
0
 public float getTotalPrice() {
   // TODO Auto-generated method stub
   float totalPrice = 0;
   if (items.size() > 0) {
     for (int i = 0; i < items.size(); i++) {
       ItemDTO item = items.get(i);
       totalPrice += item.getPrice() * item.getOrderCount();
     }
     int temp = (int) (totalPrice * 100 + 0.5);
     totalPrice = (float) (temp / 100.0);
   }
   return totalPrice;
 }