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 * The time this video was rented as long
013 */
014 private long rentTime;
015
016 /**
017 * Constructs a new VideoCassette with the given name and the current time as renting time
018 *
019 * @param key
020 * the name of the video
021 */
022 public VideoCassette(String key) {
023 super(key);
024 rentTime = ((Date) Shop.getTheShop().getTimer().getTime()).getTime();
025 }
026 /**
027 * @return the days this video is already rented, in the case of 0 days it returns 1.
028 */
029 public int getDays() {
030 long l = ((Date) Shop.getTheShop().getTimer().getTime()).getTime() - rentTime;
031 l /= 86400000;
032 if(l==0) return 1;
033 return (int) Math.ceil(l);
034 }
035
036 /**
037 * @return the cost for this video from the day of renting to the current <code>Date</code>
038 */
039 public NumberValue getCost() {
040 return (NumberValue) MainClass.RENT_VALUE_DAY.multiply(getDays());
041 }
042 }