Exemplo n.º 1
0
        public static void Main()
        {
            List <Animal> animals = new List <Animal>();

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                Animal animal = AnimalFactory.Create(command.Split(' ', StringSplitOptions.RemoveEmptyEntries));
                animals.Add(animal);
                Console.WriteLine(animal.ProduceSound());
                Food food = FoodFactory.Create(Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries));

                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            animals.ForEach(Console.WriteLine);
        }
Exemplo n.º 2
0
        public void Run()
        {
            string commad = Console.ReadLine();

            while (commad != "End")
            {
                string[] animalArgs = commad.Split();

                Animal animal = AnimalFactory.Create(animalArgs);

                string[] foodArgs = Console.ReadLine().Split();

                Foods food = FoodFactory.Create(foodArgs);

                Console.WriteLine(animal.SoundEat());

                try
                {
                    animal.Eat(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animals.Add(animal);

                commad = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 3
0
        public static void Main()
        {
            string userInput = Console.ReadLine();

            var animals = new List <BaseAnimal>();

            while (userInput != "End")
            {
                string[] animalInfo = userInput.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                var newAnimal = AnimalFactory.Create(animalInfo);
                animals.Add(newAnimal);

                string[] foodInfo = Console.ReadLine().Split(" ");
                var      food     = FoodFactory.Create(foodInfo);

                Console.WriteLine(newAnimal.ProduceSound());

                try
                {
                    newAnimal.Eat(food, food.Quantity);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                userInput = Console.ReadLine();
            }

            Console.WriteLine($"{string.Join(Environment.NewLine, animals)}");
        }
Exemplo n.º 4
0
        static void Main()
        {
            string        input;
            List <Animal> animals = new List <Animal>();

            while ((input = Console.ReadLine()) != "End")
            {
                string[] animalArgs = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                Animal animal = AnimalFactory.Create(animalArgs);

                string[] foodArgs = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                Food food = FoodFactory.Create(foodArgs);

                animal.AskForFood();
                try
                {
                    animal.Eat(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animals.Add(animal);
            }

            foreach (Animal a in animals)
            {
                Console.WriteLine(a);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] animalArgs = input.Split();
                string[] foodArgs   = Console.ReadLine().Split();

                try
                {
                    Animal animal = AnimalFactory.Create(animalArgs);
                    Console.WriteLine(animal.ProduceSound());
                    animals.Add(animal);
                    Food food = FoodFactory.Create(foodArgs);
                    animal.EatFood(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 6
0
        public static void Main()
        {
            List <Animal> animals = new List <Animal>();

            string input = Console.ReadLine();

            while (input != "End")
            {
                string[] animalArgs = input.Split();
                Animal   animal     = AnimalFactory.Create(animalArgs);
                Console.WriteLine(animal.ProduceSound());
                string[] foodArgs = Console.ReadLine().Split();
                Food     food     = FoodFactory.Create(foodArgs);
                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
                animals.Add(animal);

                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 7
0
        public static void Main()
        {
            var animals = new List <IAnimal>();

            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                var animalTokens = input.Split();
                var foodTokens   = Console.ReadLine().Split();

                IAnimal animal = AnimalFactory.Create(animalTokens);
                IFood   food   = FoodFactory.Create(foodTokens);

                Console.WriteLine(animal.ProduceSound());

                try
                {
                    animal.Eat(food, food.Quantity);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                animals.Add(animal);
            }

            animals.ForEach(a => Console.WriteLine(a));
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();
            string        input;

            while ((input = Console.ReadLine()) != "End")
            {
                var    animalTokens = ParseConsoleInput(input);
                Animal animal       = AnimalFactory.Create(animalTokens);
                animals.Add(animal);
                var  foodTokens = ParseConsoleInput(Console.ReadLine());
                Food food       = FoodFactory.Create(foodTokens);
                Console.WriteLine(animal.ProduceSound());
                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            string command = Console.ReadLine();

            while (command != "End")
            {
                try
                {
                    string[] animalArgs = command.Split();

                    Animal animal = AnimalFactory.Create(animalArgs);
                    animals.Add(animal);
                    Console.WriteLine(animal.ProduceSound());

                    string[] foodArgs = Console.ReadLine().Split();
                    Food     food     = FoodFactory.Create(foodArgs);
                    animal.Eat(food);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                command = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 10
0
        public static void Main()
        {
            var animals = new List <Animal>();

            while (true)
            {
                var input = Console.ReadLine().Split();
                if (input[0] == "End")
                {
                    break;
                }

                var animal = AnimalFactory.Create(input);
                Console.WriteLine(animal.ProduceSound());

                var foodArgs = Console.ReadLine().Split();
                var food     = FoodFactory.Create(foodArgs);

                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 11
0
        public static void Main()
        {
            List <Animal> animals = new List <Animal>();

            while (true)
            {
                string   line           = Console.ReadLine();
                string[] elementsAnimal = line.Split();

                if (line == "End")
                {
                    break;
                }

                string[]      elementsFood = Console.ReadLine().Split();
                AnimalFactory factory      = new AnimalFactory();
                Animal        animal       = factory.Create(elementsAnimal[0], elementsAnimal);
                Console.WriteLine(animal.ProducingSound());

                FoodFactory foodFactory = new FoodFactory();
                Food        food        = foodFactory.Create(elementsFood[0], elementsFood);

                try
                {
                    animal.Food(food);
                    animal.IncreasWeight(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            var animalList = new List <Animal>();

            while (true)
            {
                string[] input = Console.ReadLine().Split();
                if (input[0] == "End")
                {
                    break;
                }

                string animal = input[0];
                Food   food;
                switch (animal)
                {
                case nameof(Tiger):
                    var tiger = new Tiger(input[1], double.Parse(input[2]), input[3], input[4]);
                    Console.WriteLine(tiger.ProduceSound());

                    food = FoodFactory.Create(Console.ReadLine().Split());

                    try
                    {
                        tiger.Eat(food);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    animalList.Add(tiger);
                    break;

                case "Cat":
                    var cat = new Cat(input[1], double.Parse(input[2]), input[3], input[4]);
                    Console.WriteLine(cat.ProduceSound());
                    food = FoodFactory.Create(Console.ReadLine().Split());

                    try
                    {
                        cat.Eat(food);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    animalList.Add(cat);

                    break;

                case "Dog":
                    var dog = new Dog(input[1], double.Parse(input[2]), input[3]);
                    Console.WriteLine(dog.ProduceSound());
                    food = FoodFactory.Create(Console.ReadLine().Split());


                    try
                    {
                        dog.Eat(food);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    animalList.Add(dog);

                    break;

                case "Mouse":
                    var mice = new Mouse(input[1], double.Parse(input[2]), input[3]);
                    Console.WriteLine(mice.ProduceSound());
                    food = FoodFactory.Create(Console.ReadLine().Split());


                    try
                    {
                        mice.Eat(food);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    animalList.Add(mice);

                    break;

                case "Hen":
                    var hen = new Hen(input[1], double.Parse(input[2]), double.Parse(input[3]));
                    Console.WriteLine(hen.ProduceSound());
                    food = FoodFactory.Create(Console.ReadLine().Split());

                    try
                    {
                        hen.Eat(food);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    animalList.Add(hen);

                    break;

                case "Owl":
                    var owl = new Owl(input[1], double.Parse(input[2]), double.Parse(input[3]));
                    Console.WriteLine(owl.ProduceSound());
                    food = FoodFactory.Create(Console.ReadLine().Split());

                    try
                    {
                        owl.Eat(food);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    animalList.Add(owl);

                    break;

                default:
                    break;
                }
            }
            animalList.ForEach(Console.WriteLine);

            //var hen = new Hen("GOGo", 2.5, 30);
            //Console.WriteLine(hen);
        }