public static void CollectInput(Farm farm) { do { UpdateFacilities(farm); if (_facilities.Count == 0) { StandardMessages.ShowMessage("No available facilities to process."); return; } // Select a house IGathering selectedHouse = SelectHouse(farm.EggGatherer); // Select quantity of resources to process int quantity = SelectQuantity(farm.EggGatherer.Capacity, selectedHouse); // // Add selected resources to hopper selectedHouse.SendToBasket(quantity, farm); } while (AddMore(farm.EggGatherer.Capacity)); farm.EggGatherer.Gather(); }
private static int SelectQuantity(int capacity, IGathering house) { // int[] numbers = { capacity, group.Count() }; int numAnimals = house.NumAnimals; int eggsPerAnimal = 0; if (house is GrazingField field) { numAnimals = field.NumOstriches; eggsPerAnimal = 3; } if (house is ChickenHouse) { eggsPerAnimal = 7; } if (house is DuckHouse) { eggsPerAnimal = 6; } double maxAvailable = Math.Floor((double)capacity / eggsPerAnimal); int[] animalArray = { (int)maxAvailable, numAnimals }; int maxAnimals = animalArray.Min(); Program.DisplayBanner(); Console.WriteLine($"Egg Gatherer can gather eggs from {maxAnimals} animals."); bool doOver; do { doOver = false; Console.WriteLine(); Console.WriteLine($"How many animals should be selected?"); Console.Write("> "); string input = Console.ReadLine(); int quantity; try { quantity = Int32.Parse(input); if (quantity <= maxAnimals) { return(quantity); } else { throw new Exception(); } } catch (Exception ex) { Program.ShowMessage("Invalid entry"); doOver = true; } } while (doOver); // This line will never run return(0); }