public PromoPackage(Book book1, Book book2, int discountAmount, DiscountType discountType) { this.book1 = book1; this.book2 = book2; this.discountAmount = discountAmount; this.discountType = discountType; }
/// <summary> /// Gets the number of books in the inventory. /// </summary> /// <param name="book"></param> /// <returns></returns> public static int CountBooks(Book book) { if (!books.ContainsKey(book)) { return 0; } return books[book]; }
public void AddBook(int amount, Book book) { int currentAmount = 0; if (contents.ContainsKey(book)) { currentAmount = contents[book]; } currentAmount += amount; contents[book] = currentAmount; }
public static void AddBook(Book book, int amount) { if (!books.ContainsKey(book)) { books.Add(book, 0); } int currentAmount = books[book]; currentAmount += amount; books[book] = currentAmount; }
/// <summary> /// Deducts the amount given for the specified book in the inventory. /// </summary> /// <param name="book"></param> /// <param name="amount"></param> public static void DeductInventory(Book book, int amount) { int stock = books[book]; if (stock - amount < 0) { throw new ArgumentException("Not enough books in stock: current stock is " + stock + ", trying to deduct " + amount); } stock -= amount; books[book] = stock; }
public int GetAmount(Book book) { return contents[book]; }
public bool ContainsBook(Book book) { return contents.ContainsKey(book); }