001 package videoautomat; 002 import java.util.Date; 003 004 import sale.Shop; 005 import data.NumberValue; 006 import data.ooimpl.StockItemImpl; 007 /** 008 * This class implements a StockItem, representing a rented video, including the <code>Date</code> when it was rented 009 */ 010 public class VideoCassette extends StockItemImpl { 011 /** 012 * ID for Serialization. 013 */ 014 private static final long serialVersionUID = 5691570511078222257L; 015 /* 016 * The time this video was rented as long 017 */ 018 private long rentTime; 019 020 /** 021 * Constructs a new VideoCassette with the given name and the current time as renting time 022 * 023 * @param key 024 * the name of the video 025 */ 026 public VideoCassette(String key) { 027 super(key); 028 rentTime = ((Date) Shop.getTheShop().getTimer().getTime()).getTime(); 029 } 030 /** 031 * @return the days this video is already rented, in the case of 0 days it returns 1. 032 */ 033 public int getDays() { 034 long l = ((Date) Shop.getTheShop().getTimer().getTime()).getTime() - rentTime; 035 l /= 86400000; 036 if(l==0) return 1; 037 return (int) Math.ceil(l); 038 } 039 040 /** 041 * @return the cost for this video from the day of renting to the current <code>Date</code> 042 */ 043 public NumberValue getCost() { 044 return (NumberValue) MainClass.RENT_VALUE_DAY.multiply(getDays()); 045 } 046 }