public static void SpendBells(IslandResident islandResident) { Console.WriteLine("Please select an item from the catalog:"); Console.WriteLine(" "); foreach (var item in items) { Console.WriteLine(item.Name); } var selectedItem = Console.ReadLine(); foreach (var item in items) { if (selectedItem == item.Name) { if (islandResident.Bells < item.Price) { Console.WriteLine("Oh, it seems you haven't enough bells to buy that item. Take a stroll around the island and see if you can find a money tree!"); Menu.ShowMenu(); break; } if (item.ItemsLeft == 0) { Console.WriteLine("Oh, we're sorry. That item is no longer available. You have to act fast before items sell out."); SpendBells(islandResident); break; } Console.WriteLine("Your order has been placed! Your order will be delivered shortly to your home through the mail."); islandResident.Bells -= item.Price; Menu.ShowMenu(); } } }
public static void Deposit(int amount, IslandResident islandResident) { if (amount > 0) { islandResident.Bells += amount; Console.WriteLine(""); Console.WriteLine($"We added {amount} bells to your savings."); } else { Console.WriteLine("Please enter an amount larger than 0."); } }
static void Main(string[] args) { var bells = 2000; NookShoppingCatalog nookShoppingCatalog = new NookShoppingCatalog(); ABD abd = new ABD(); IslandResident islandResident = new IslandResident(bells); Menu.ShowMenu(); while (true) { var selection = Console.ReadLine(); switch (selection) { case "1": Console.WriteLine("How many bells would you like to deposit?"); int.TryParse(Console.ReadLine(), out var amount); ABD.Deposit(amount, islandResident); Menu.ShowMenu(); break; case "2": Console.WriteLine(""); Console.WriteLine("Welcome to Nook Shopping!"); Console.WriteLine("Order special goods or goods from the daily selection here."); Console.WriteLine(""); NookShoppingCatalog.SpendBells(islandResident); break; case "3": ABD.Savings(islandResident); Menu.ShowMenu(); break; default: Console.WriteLine("Please select option 1, 2, or 3."); break; } } }
public static void Savings(IslandResident islandResident) { Console.WriteLine($"You have {islandResident.Bells} bells in your savings."); }