public void BorrowPeriodical(Periodical periodical) { int periodicalCount = 0; foreach (var element in _itemList) { if (element is Periodical) { periodicalCount++; } } if (_itemList.Count >= 3) { Console.WriteLine("Too many items borrowed, only 3 items can be borrowed at a time"); } else if (periodicalCount >= 2) { Console.WriteLine("Too many periodicals borrowed, only 2 periodicals can be borrowed at a time"); } else { _itemList.Add(periodical); } }
static void Main(string[] args) { Patron patron = new Patron(); Book book = new Book("796.6", "The Univeristy of Chicago Press", "Cycling Science", "Max Glaskin"); Periodical periodical = new Periodical("231.2", "MAD Publishing", "MAD Magazine", "623"); patron.BorrowBook(book); patron.BorrowPeriodical(periodical); patron.BorrowBook(book); patron.BorrowBook(book); patron.BorrowPeriodical(periodical); Console.WriteLine("\nBorrowed items:"); foreach (var element in patron.itemList) { Console.WriteLine(element.Title); } }