Example #1
0
 public void returnDvd(int id) throws SQLException {
   List<Dvd> list = dd.findAll();
   Date date = new Date();
   Dvd reDvd = null;
   for (int i = 0; i < list.size(); i++) {
     if (list.get(i).getId() == id) {
       reDvd = list.get(i);
       break;
     }
   }
   if (reDvd == null) {
     System.out.println("未找到该DVD!");
   } else if (reDvd.getState() == 0) {
     reDvd.setReturnDvd(date);
     long day = date.getTime() - reDvd.getBorrowDvd().getTime();
     long money = day / 1000 / 60 / 60 / 24;
     reDvd.setBorrowCount(reDvd.getBorrowCount());
     reDvd.setState(1);
     reDvd.setBorrowDvd(null);
     dd.update(reDvd);
     System.out.println("恭喜!归还DVD《" + reDvd.getName() + "》成功!");
     System.out.println("共借出" + money + "天,请支付:" + money + "元!");
   } else {
     System.out.println("输入有误!");
   }
 }
Example #2
0
 public void borrowDvd(int id) throws SQLException {
   List<Dvd> list = dd.findAll();
   Date date = new Date();
   Dvd borDvd = null;
   for (int i = 0; i < list.size(); i++) {
     if (list.get(i).getId() == id) {
       borDvd = list.get(i);
       break;
     }
   }
   if (borDvd == null) {
     System.out.println("未找到该DVD!");
   } else if (borDvd.getState() == 1) {
     borDvd.setBorrowDvd(date);
     borDvd.setReturnDvd(null);
     borDvd.setBorrowCount(borDvd.getBorrowCount() + 1);
     borDvd.setState(0);
     dd.update(borDvd);
     System.out.println("恭喜!借出DVD《" + borDvd.getName() + "》成功!");
   } else {
     System.out.println("该DVD已借出,不可借!");
   }
 }