Пример #1
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());
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            while (true)
            {
                string input = Console.ReadLine();

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

                string[] animalArgs = input.Split();

                Animal animal = AnimalFactory.Create(animalArgs);

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

                Food food = FoodFactory.Create(foodArgs);

                Console.WriteLine(animal.ProduceSound());

                animals.Add(animal);

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

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            var    animals = new List <Animal>();
            string inputLine;

            while ((inputLine = Console.ReadLine()) != "End")
            {
                try
                {
                    var input = inputLine.Split();
                    if (input.Length == 2)
                    {
                        var foodName = input[0];
                        var quantity = int.Parse(input[1]);
                        var food     = FoodFactory.GetFood(foodName, quantity);
                        var animal   = animals.Last();
                        animal.Eate(food);
                        continue;
                    }
                    var    animalType   = input[0];
                    var    animalName   = input[1];
                    var    animalWeight = double.Parse(input[2]);
                    var    livingRegion = input[3];
                    string breed        = null;
                    if (input.Length == 5)
                    {
                        breed = input[4];
                    }
                    animals.Add(AnimalFactory.GetAnimal(animalType, animalName, animalWeight, livingRegion, breed));
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Пример #4
0
        public static void Main()
        {
            List <Animal> animals = new List <Animal>();

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

                if (info[0] == "End")
                {
                    break;
                }

                Animal animal = AnimalFactory.CreateAnimal(info);

                info = Console.ReadLine().Split();
                Food food = FoodFactory.CreateFood(info);

                Console.WriteLine(animal.MakeSound());

                try
                {
                    animal.Feed(food);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }

                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
        static void Main(string[] args)
        {
            string inputLine;

            while ((inputLine = Console.ReadLine()) != "End")
            {
                var animalTokens = inputLine.Split(new[] { '\t', ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                var foodTokens   = Console.ReadLine().Split(new[] { '\t', ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                Animal animal = AnimalFactory.GetAnimal(animalTokens);
                Food   food   = FoodFactory.GetFood(foodTokens);

                Console.WriteLine(animal.MakeSound());
                try
                {
                    animal.Eat(food);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                Console.WriteLine(animal);
            }
        }
Пример #6
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);
        }
Пример #7
0
        public Engine()
        {
            this.animals = new List <Animal>();

            this.foodFactory = new FoodFactory();
        }