public void Add(Book book) { _books.Add(book); }
private bool ShouldApplyDiscount(Book book) { return (_books.Any(x => x.GetType() != book.GetType())); }
public void Add(Book book) { _books.Add(book); _total += BOOK_PRICE; if (ShouldApplyDiscount(book)) { ApplyDiscount(new PercentageDiscount(5)); } }
private void AddBook(Book book) { if (ContainsBook(book)) { throw new ArgumentException("This set already contains this book."); } Books[book.PositionInSet - 1] = book; }
private static BookSet ShortestSetWithoutBook(IEnumerable<BookSet> sets, Book book) { return sets.OrderBy(s => s.Books.Count(b => b != null)) .FirstOrDefault(s => !s.ContainsBook(book)); }
private static void AddBookToShortestSetThatDoesNotContainIt(IEnumerable<BookSet> sets, Book book) { var shortestCandidateSet = ShortestSetWithoutBook(sets, book); shortestCandidateSet.AddBook(book); }
private bool ContainsBook(Book book) { return Books.Length >= book.PositionInSet && Books.ElementAt(book.PositionInSet -1) != null; }
private BookSet(int setSize) { Books = new Book[setSize]; }