Пример #1
0
        static void Main(string[] args)
        {
            var listAnimals = new List <Animal>();
            var animalInput = Console.ReadLine().Split();

            while (animalInput[0] != "End")
            {
                var type      = animalInput[0];
                var name      = animalInput[1];
                var weight    = double.Parse(animalInput[2]);
                var food      = Console.ReadLine().Split();
                var foodType  = food[0];
                var foodCount = int.Parse(food[1]);
                if (animalInput.Count() == 4)
                {
                    if (double.TryParse(animalInput[3], out double wingSize))
                    {
                        if (type == "Hen")
                        {
                            var hen = new Hen(name, weight, wingSize);
                            Console.WriteLine(hen.MakeSound());
                            hen.EatFood(foodCount, hen.Multiplier);
                            listAnimals.Add(hen);
                        }
                        else
                        {
                            var owl = new Owl(name, weight, wingSize);
                            Console.WriteLine(owl.MakeSound());
                            if (foodType == "Meat")
                            {
                                owl.EatFood(foodCount, owl.Multiplier);
                            }
                            else
                            {
                                Console.WriteLine(owl.AnimalDoesntEat(foodType));
                            }
                            listAnimals.Add(owl);
                        }
                    }
                    else
                    {
                        var region = animalInput[3];
                        if (type == "Dog")
                        {
                            var dog = new Dog(name, weight, region);
                            Console.WriteLine(dog.MakeSound());
                            if (foodType == "Meat")
                            {
                                dog.EatFood(foodCount, dog.Multiplier);
                            }
                            else
                            {
                                Console.WriteLine(dog.AnimalDoesntEat(foodType));
                            }
                            listAnimals.Add(dog);
                        }
                        else
                        {
                            var mouse = new Mouse(name, weight, region);
                            Console.WriteLine(mouse.MakeSound());
                            if (foodType == "Vegetable" || foodType == "Fruit")
                            {
                                mouse.EatFood(foodCount, mouse.Multiplier);
                            }
                            else
                            {
                                Console.WriteLine(mouse.AnimalDoesntEat(foodType));
                            }
                            listAnimals.Add(mouse);
                        }
                    }
                }
                else
                {
                    var region = animalInput[3];
                    var breed  = animalInput[4];
                    if (type == "Cat")
                    {
                        var cat = new Cat(name, weight, region, breed);
                        Console.WriteLine(cat.MakeSound());
                        if (foodType == "Meat" || foodType == "Vegetable")
                        {
                            cat.EatFood(foodCount, cat.Multiplier);
                        }
                        else
                        {
                            Console.WriteLine(cat.AnimalDoesntEat(foodType));
                        }
                        listAnimals.Add(cat);
                    }
                    else
                    {
                        var tiger = new Tiger(name, weight, region, breed);
                        Console.WriteLine(tiger.MakeSound());
                        if (foodType == "Meat")
                        {
                            tiger.EatFood(foodCount, tiger.Multiplier);
                        }
                        else
                        {
                            Console.WriteLine(tiger.AnimalDoesntEat(foodType));
                        }
                        listAnimals.Add(tiger);
                    }
                }
                animalInput = Console.ReadLine().Split();
            }

            foreach (var item in listAnimals)
            {
                Console.WriteLine(item.ToString());
            }
        }
        static void Main()
        {
            var animalInfo = Console.ReadLine()
                             .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            while (!animalInfo[0].Equals("End"))
            {
                var foodInfo = Console.ReadLine()
                               .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                var animalName         = animalInfo[1];
                var animalWeight       = double.Parse(animalInfo[2]);
                var animalLivingRegion = animalInfo[3];

                var foodType     = foodInfo[0];
                var foodQuantity = int.Parse(foodInfo[1]);

                Food food;
                if (foodType.Equals("Vegetable"))
                {
                    food = new Vegetable(foodQuantity);
                }
                else
                {
                    food = new Meat(foodQuantity);
                }

                switch (animalInfo[0])
                {
                case "Cat":
                    var catBreed = animalInfo[4];

                    var cat = new Cat(animalName, animalWeight, animalLivingRegion, catBreed);
                    cat.MakeSound();
                    cat.Eat(food);
                    Console.WriteLine(cat);
                    break;

                case "Tiger":
                    var tiger = new Tiger(animalName, animalWeight, animalLivingRegion);
                    tiger.MakeSound();
                    tiger.Eat(food);
                    Console.WriteLine(tiger);
                    break;

                case "Zebra":
                    var zebra = new Zebra(animalName, animalWeight, animalLivingRegion);
                    zebra.MakeSound();
                    zebra.Eat(food);
                    Console.WriteLine(zebra);
                    break;

                case "Mouse":
                    var mouse = new Mouse(animalName, animalWeight, animalLivingRegion);
                    mouse.MakeSound();
                    mouse.Eat(food);
                    Console.WriteLine(mouse);
                    break;
                }

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