private void addToy(Shelf <Toy> shelf) { Console.WriteLine("Please enter the toy name."); string name = Console.ReadLine(); Console.WriteLine("Please enter the price."); int price = -1; int.TryParse(Console.ReadLine(), out price); if (price > 0) { Toy toy = new Toy(name, price); shelf.Add(toy); } else { Console.WriteLine("Invalid price"); } }
private void addBook(Shelf <Book> shelf) { Console.WriteLine("Please enter the book name."); string name = Console.ReadLine(); Console.WriteLine("Please enter the author's name."); string author = Console.ReadLine(); Console.WriteLine("Please enter the number of pages."); int pages = -1; int.TryParse(Console.ReadLine(), out pages); if (pages > 0) { Book book = new Book(name, author, pages); shelf.Add(book); } else { Console.WriteLine("Invalid number of pages"); } }