public void ProcessResults(List <IResource> resProcessed) { Dictionary <string, double> eggsProduced = new Dictionary <string, double>(); resProcessed.ForEach(animal => { IEggProducing resource = (IEggProducing)animal; try { eggsProduced.Add(resource.GetType().Name, resource.CollectEggs()); } catch (Exception) { eggsProduced[resource.GetType().Name] += resource.CollectEggs(); } }); foreach (KeyValuePair <string, double> animal in eggsProduced) { System.Console.WriteLine($"{animal.Value} {animal.Key} eggs were collected"); } }
public static void CollectInput(Farm farm, IEggProducing animal) { Utils.Clear(); bool Placed = false; while (Placed == false) { for (int i = 0; i < farm.DuckHouses.Count; i++) { Console.WriteLine(farm.DuckHouses[i].Capacity == farm.DuckHouses[i].ducksInDuckHouse ? $"{i + 1}. Duck House (Full)" : $"{i + 1}. Duck House ({farm.DuckHouses[i].ducksInDuckHouse} Ducks)"); } Console.WriteLine(); Console.WriteLine($"Where would you like to place the {animal.GetType().Name}?"); Console.Write("> "); try { int choice = Int32.Parse(Console.ReadLine()); if (farm.DuckHouses[choice - 1].ducksInDuckHouse == farm.DuckHouses[choice - 1].Capacity) { Console.WriteLine("**** That facility is not large enough ****"); Console.WriteLine("**** Please choose another one ****"); choice = Int32.Parse(Console.ReadLine()); } else { farm.DuckHouses[choice - 1].AddResource(animal); Placed = true; Console.WriteLine("Break Point"); } } catch (Exception e) { Console.WriteLine("Please enter only numbers"); } } }