public void Run()
        {
            string command = Console.ReadLine();

            while (command != "End")
            {
                string  foodInput = Console.ReadLine();
                IAnimal animal    = GetAnimal(command);
                IFood   food      = GetFood(foodInput);
                Console.WriteLine(animal.AskFood());

                try
                {
                    animal.Feed(food);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine(ioe.Message);
                }

                command = Console.ReadLine();
            }

            PrintOutput();
        }
Exemplo n.º 2
0
        public void Run()
        {
            string input;

            while ((input = Read()) != "End")
            {
                try
                {
                    IAnimal animal = animalFactory.CreateAnimal(input.Split());

                    IFood food = foodFactory.CreateFood(Read().Split());

                    animals.Add(animal);
                    Print(animal.AskFood());

                    animal.Eat(food);
                }
                catch (ArgumentException ae)
                {
                    Print(ae.Message);
                }
            }

            animals.ForEach(a => Print(a.ToString()));
        }