Пример #1
0
        public static void Main()
        {
            var result = new StringBuilder();

            var animalList = new List <Animal>();

            var typeOfAnimals = new Dictionary <string, List <string> >();

            AddTypes(typeOfAnimals);

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

                string[] animalToken = input.Split(' ');

                string type = animalToken[0];

                input = Console.ReadLine();

                string[] token = input.Split(' ');

                string typeOfFood = token[0];
                int    quantity   = int.Parse(token[1]);

                try
                {
                    // Birds
                    if (typeOfAnimals["Bird"].Contains(type))
                    {
                        string name         = animalToken[1];
                        double animalWeight = double.Parse(animalToken[2]);
                        double wingSize     = double.Parse(animalToken[3]);

                        switch (type)
                        {
                        case "Owl":
                            Owl owl = new Owl(name, animalWeight, wingSize);
                            result.AppendLine(owl.ProduceSound());
                            animalList.Add(owl);
                            owl.Eat(typeOfFood, quantity);
                            break;

                        case "Hen":
                            Hen hen = new Hen(name, animalWeight, wingSize);
                            result.AppendLine(hen.ProduceSound());
                            animalList.Add(hen);
                            hen.Eat(typeOfFood, quantity);
                            break;
                        }
                    }

                    // Mammals
                    if (typeOfAnimals["Mammal"].Contains(type))
                    {
                        string mammalName         = animalToken[1];
                        double mammalAnimalWeight = double.Parse(animalToken[2]);
                        string mammalLivingRegion = animalToken[3];

                        switch (type)
                        {
                        case "Mouse":
                            Mouse mouse = new Mouse(mammalName, mammalAnimalWeight, mammalLivingRegion);
                            animalList.Add(mouse);
                            result.AppendLine(mouse.ProduceSound());
                            mouse.Eat(typeOfFood, quantity);
                            break;

                        case "Dog":
                            Dog dog = new Dog(mammalName, mammalAnimalWeight, mammalLivingRegion);
                            result.AppendLine(dog.ProduceSound());
                            animalList.Add(dog);
                            dog.Eat(typeOfFood, quantity);
                            break;
                        }
                    }

                    // Feline
                    if (typeOfAnimals["Feline"].Contains(type))
                    {
                        string felineName         = animalToken[1];
                        double felineWeight       = double.Parse(animalToken[2]);
                        string felineLivingRegion = animalToken[3];
                        string felineBreed        = animalToken[4];

                        switch (type)
                        {
                        case "Cat":
                            Cat cat = new Cat(felineName, felineWeight, felineLivingRegion, felineBreed);
                            animalList.Add(cat);
                            result.AppendLine(cat.ProduceSound());
                            cat.Eat(typeOfFood, quantity);
                            break;

                        case "Tiger":
                            Tiger tiger = new Tiger(felineName, felineWeight, felineLivingRegion, felineBreed);
                            animalList.Add(tiger);
                            result.AppendLine(tiger.ProduceSound());
                            tiger.Eat(typeOfFood, quantity);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    result.AppendLine(ex.Message);
                }
            }

            Console.Write(result.ToString());

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

            while (input.ToLower() != "end")
            {
                var      tokens = input.Split(" ");
                string[] foods  = Console.ReadLine().Split(" ");

                var animalType = tokens[0];
                var foodType   = foods[0];
                int food       = int.Parse(foods[1]);

                switch (animalType)
                {
                case "Cat":
                    Cat cat = new Cat(tokens[1], double.Parse(tokens[2]), tokens[3], tokens[4]);
                    animals.Add(cat);
                    cat.AskForFood();
                    if (foodType == "Vegetable" || foodType == "Meat")
                    {
                        cat.EatFood(food);
                        cat.IncreaseWeight();
                    }
                    else
                    {
                        Console.WriteLine($"Cat does not eat {foodType}!");
                    }
                    break;

                case "Tiger":
                    Tiger tiger = new Tiger(tokens[1], double.Parse(tokens[2]), tokens[3], tokens[4]);
                    animals.Add(tiger);
                    tiger.AskForFood();
                    if (foodType == "Meat")
                    {
                        tiger.EatFood(food);
                        tiger.IncreaseWeight();
                    }
                    else
                    {
                        Console.WriteLine($"Tiger does not eat {foodType}!");
                    }
                    break;

                case "Dog":
                    Dog dog = new Dog(tokens[1], double.Parse(tokens[2]), tokens[3]);
                    animals.Add(dog);
                    dog.AskForFood();
                    if (foodType == "Meat")
                    {
                        dog.EatFood(food);
                        dog.IncreaseWeight();
                    }
                    else
                    {
                        Console.WriteLine($"Dog does not eat {foodType}!");
                    }
                    break;

                case "Mouse":
                    Mouse mouse = new Mouse(tokens[1], double.Parse(tokens[2]), tokens[3]);
                    animals.Add(mouse);
                    mouse.AskForFood();
                    if (foodType == "Vegetable" || foodType == "Fruit")
                    {
                        mouse.EatFood(food);
                        mouse.IncreaseWeight();
                    }
                    else
                    {
                        Console.WriteLine($"Mouse does not eat {foodType}!");
                    }
                    break;

                case "Hen":
                    Hen hen = new Hen(tokens[1], double.Parse(tokens[2]), double.Parse(tokens[3]));
                    animals.Add(hen);
                    hen.AskForFood();
                    hen.EatFood(food);
                    hen.IncreaseWeight();
                    break;

                case "Owl":
                    Owl owl = new Owl(tokens[1], double.Parse(tokens[2]), double.Parse(tokens[3]));
                    animals.Add(owl);
                    owl.AskForFood();
                    if (foodType == "Meat")
                    {
                        owl.EatFood(food);
                        owl.IncreaseWeight();
                    }
                    else
                    {
                        Console.WriteLine($"Owl does not eat {foodType}!");
                    }
                    break;
                }

                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Пример #3
0
        public static void Main()
        {
            List <Animal> animals = new List <Animal>();
            List <Food>   foods   = new List <Food>();

            int lineCounter = -1;

            while (true)
            {
                lineCounter++;//N.B. += 1
                string cmd = Console.ReadLine();
                if (cmd == "End")
                {
                    break;
                }

                string[] cmdArgs = cmd.Split(' ', StringSplitOptions.RemoveEmptyEntries);

                switch (cmdArgs[0])
                {
                case "Owl":
                    var owl = new Owl(cmdArgs[1], double.Parse(cmdArgs[2]), double.Parse(cmdArgs[3]));
                    animals.Add(owl);
                    break;

                case "Hen":
                    var hen = new Hen(cmdArgs[1], double.Parse(cmdArgs[2]), double.Parse(cmdArgs[3]));
                    animals.Add(hen);
                    break;

                case "Mouse":
                    var mouse = new Mouse(cmdArgs[1], double.Parse(cmdArgs[2]), cmdArgs[3]);
                    animals.Add(mouse);
                    break;

                case "Dog":
                    var dog = new Dog(cmdArgs[1], double.Parse(cmdArgs[2]), cmdArgs[3]);
                    animals.Add(dog);
                    break;

                case "Cat":
                    var cat = new Cat(cmdArgs[1], double.Parse(cmdArgs[2]), cmdArgs[3], cmdArgs[4]);
                    animals.Add(cat);
                    break;

                case "Tiger":
                    var tiger = new Tiger(cmdArgs[1], double.Parse(cmdArgs[2]), cmdArgs[3], cmdArgs[4]);
                    animals.Add(tiger);
                    break;

                case "Vegetable":
                    var vegetable = new Vegetable(int.Parse(cmdArgs[1]));
                    foods.Add(vegetable);
                    break;

                case "Fruit":
                    var fruit = new Fruit(int.Parse(cmdArgs[1]));
                    foods.Add(fruit);
                    break;

                case "Meat":
                    var meat = new Meat(int.Parse(cmdArgs[1]));
                    foods.Add(meat);
                    break;

                case "Seeds":
                    var seeds = new Seeds(int.Parse(cmdArgs[1]));
                    foods.Add(seeds);
                    break;
                }
            }

            for (int i = 0; i < animals.Count; i++)
            {
                try
                {
                    Console.WriteLine(animals[i].AskForFood());
                    animals[i].Eat(foods[i]);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

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

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

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

                Animal animal = null;
                Food   food   = null;

                string type   = animalInput[0];
                string name   = animalInput[1];
                double weight = double.Parse(animalInput[2]);

                switch (type)
                {
                case "Owl":
                    animal = new Owl(name, weight, double.Parse(animalInput[3]));
                    break;

                case "Hen":
                    animal = new Hen(name, weight, double.Parse(animalInput[3]));
                    break;

                case "Mouse":
                    animal = new Mouse(name, weight, animalInput[3]);
                    break;

                case "Dog":
                    animal = new Dog(name, weight, animalInput[3]);
                    break;

                case "Cat":
                    animal = new Cat(name, weight, animalInput[3], animalInput[4]);
                    break;

                case "Tiger":
                    animal = new Tiger(name, weight, animalInput[3], animalInput[4]);
                    break;

                default:
                    break;
                }

                string foodType     = foodInput[0];
                int    foodQuantity = int.Parse(foodInput[1]);

                switch (foodType)
                {
                case "Fruit":
                    food = new Fruit(foodQuantity);
                    break;

                case "Vegetable":
                    food = new Vegetable(foodQuantity);
                    break;

                case "Meat":
                    food = new Meat(foodQuantity);
                    break;

                case "Seeds":
                    food = new Seeds(foodQuantity);
                    break;

                default:
                    break;
                }

                Console.WriteLine(animal.AskForFood());
                animal.Feed(food);

                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            var input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                var animalInformation = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var foodInformation   = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                Animal currentAnimal = null;
                Food   currentFood   = null;

                var animalType   = animalInformation[0];
                var animalName   = animalInformation[1];
                var animalWeight = double.Parse(animalInformation[2]);
                var animalRegion = animalInformation[3];
                var animalBreed  = string.Empty;

                if (animalType == "Cat")
                {
                    animalBreed   = animalInformation[4];
                    currentAnimal = new Cat(animalName, animalType, animalWeight, animalRegion, animalBreed);
                }
                else
                {
                    switch (animalType)
                    {
                    case "Tiger":
                        currentAnimal = new Tiger(animalName, animalType, animalWeight, animalRegion);
                        break;

                    case "Zebra":
                        currentAnimal = new Zebra(animalName, animalType, animalWeight, animalRegion);
                        break;

                    case "Mouse":
                        currentAnimal = new Mouse(animalName, animalType, animalWeight, animalRegion);
                        break;
                    }
                }

                var foodType   = foodInformation[0];
                var foodAmount = int.Parse(foodInformation[1]);

                if (foodType == "Vegetable")
                {
                    currentFood = new Vegetable(foodAmount);
                }
                else if (foodType == "Meat")
                {
                    currentFood = new Meat(foodAmount);
                }

                Console.WriteLine(currentAnimal.MakeSound());

                try
                {
                    currentAnimal.Eat(currentFood);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine(ioe.Message);
                }

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

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

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

                var    data       = cmd.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string animalType = data[0];
                string name       = data[1];
                double weight     = double.Parse(data[2]);

                Animal animal = null;

                switch (animalType)
                {
                case "Owl":
                {
                    int wingSize = int.Parse(data[3]);

                    animal = new Owl(name, weight, wingSize);
                    break;
                }

                case "Hen":
                {
                    int wingSize = int.Parse(data[3]);

                    animal = new Hen(name, weight, wingSize);
                    break;
                }

                case "Mouse":
                {
                    string region = data[3];

                    animal = new Mouse(name, weight, region);
                    break;
                }

                case "Dog":
                {
                    string region = data[3];

                    animal = new Dog(name, weight, region);
                    break;
                }

                case "Cat":
                {
                    string region = data[3];
                    string breed  = data[4];

                    animal = new Cat(name, weight, region, breed);
                    break;
                }

                case "Tiger":
                {
                    string region = data[3];
                    string breed  = data[4];

                    animal = new Tiger(name, weight, region, breed);
                    break;
                }

                default:
                    break;
                }

                Console.WriteLine(animal.ProduceSound());

                var foodData = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string foodName = foodData[0];
                int    foodNum  = int.Parse(foodData[1]);

                Food food = null;

                switch (foodName)
                {
                case "Fruit":
                {
                    food = new Fruit(foodNum);

                    break;
                }

                case "Meat":
                {
                    food = new Meat(foodNum);
                    break;
                }

                case "Seeds":
                {
                    food = new Seeds(foodNum);
                    break;
                }

                case "Vegetable":
                {
                    food = new Vegetable(foodNum);
                    break;
                }

                default:
                    break;
                }

                animal.Feed(food);
                animals.Add(animal);
            }

            foreach (var beast in animals)
            {
                Console.WriteLine(beast.ToString());
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            var rowCounter = 0;
            var animals    = new List <IAnimal>();

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

                if (rowCounter % 2 == 0)
                {
                    var animalInfo   = input.Split();
                    var animalType   = animalInfo[0];
                    var animalName   = animalInfo[1];
                    var animalWeight = decimal.Parse(animalInfo[2]);

                    var foodInfo = Console.ReadLine().Split();
                    var foodName = foodInfo[0];
                    //var vegetable = new Vegetable(4);
                    //var typePath = vegetable.GetType().FullName;
                    //var foodType = Type.GetType(typePath);
                    var foodType     = Type.GetType($"WildFarm.Foods.{foodName}");
                    var foodQuantity = int.Parse(foodInfo[1]);
                    var food         = Activator.CreateInstance(foodType, new Object[] { foodQuantity });
                    //var food = new Vegetable(int.Parse(foodInfo[1]));


                    if (animalType == "Tiger")
                    {
                        var livingRegion = animalInfo[3];
                        var breed        = animalInfo[4];
                        var tiger        = new Tiger(animalName, animalWeight, livingRegion, breed);
                        Console.WriteLine(tiger.AskForFood());
                        TryEatFood(tiger, (IFood)food);
                        animals.Add(tiger);
                    }
                    else if (animalType == "Cat")
                    {
                        var livingRegion = animalInfo[3];
                        var breed        = animalInfo[4];
                        var cat          = new Cat(animalName, animalWeight, livingRegion, breed);
                        Console.WriteLine(cat.AskForFood());
                        TryEatFood(cat, (IFood)food);
                        animals.Add(cat);
                    }
                    else if (animalType == "Owl")
                    {
                        var wingSize = decimal.Parse(animalInfo[3]);
                        var owl      = new Owl(animalName, animalWeight, wingSize);
                        Console.WriteLine(owl.AskForFood());
                        TryEatFood(owl, (IFood)food);
                        animals.Add(owl);
                    }
                    else if (animalType == "Hen")
                    {
                        var wingSize = decimal.Parse(animalInfo[3]);
                        var hen      = new Hen(animalName, animalWeight, wingSize);
                        Console.WriteLine(hen.AskForFood());
                        TryEatFood(hen, (IFood)food);
                        animals.Add(hen);
                    }
                    else if (animalType == "Mouse")
                    {
                        var livingRegion = animalInfo[3];
                        var mouse        = new Mouse(animalName, animalWeight, livingRegion);
                        Console.WriteLine(mouse.AskForFood());
                        TryEatFood(mouse, (IFood)food);
                        animals.Add(mouse);
                    }
                    else if (animalType == "Dog")
                    {
                        var livingRegion = animalInfo[3];
                        var dog          = new Dog(animalName, animalWeight, livingRegion);
                        Console.WriteLine(dog.AskForFood());
                        TryEatFood(dog, (IFood)food);
                        animals.Add(dog);
                    }
                }

                rowCounter += 2;
            }

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

            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] animal = input.Split();
                string   type   = animal[0];
                string   name   = animal[1];
                double   weight = double.Parse(animal[2]);

                string[] foods    = Console.ReadLine().Split();
                string   typeFood = foods[0];
                int      quantity = int.Parse(foods[1]);

                Animal animals = null;
                switch (type)
                {
                case "Cat":
                    string livingRegionCat = animal[3];
                    string breedCat        = animal[4];
                    animals = new Cat(name, weight, livingRegionCat, breedCat);
                    break;

                case "Tiger":
                    string livingRegionTiger = animal[3];
                    string breedTiger        = animal[4];
                    animals = new Tiger(name, weight, livingRegionTiger, breedTiger);
                    break;

                case "Dog":
                    string livingRegionDog = animal[3];
                    animals = new Dog(name, weight, livingRegionDog);
                    break;

                case "Mouse":
                    string livingRegionMouse = animal[3];
                    animals = new Mouse(name, weight, livingRegionMouse);
                    break;

                case "Hen":
                    double wingSizeHen = double.Parse(animal[3]);
                    animals = new Hen(name, weight, wingSizeHen);
                    break;

                case "Owl":
                    double wingSizeOwl = double.Parse(animal[3]);
                    animals = new Owl(name, weight, wingSizeOwl);
                    break;

                default:
                    break;
                }
                Console.WriteLine(animals.Sound());
                animalsCollect.Add(animals);

                Food food = null;
                try
                {
                    switch (typeFood)
                    {
                    case "Vegetable":
                        food = new Vegetable(quantity);
                        break;

                    case "Fruit":
                        food = new Fruit(quantity);
                        break;

                    case "Meat":
                        food = new Meat(quantity);
                        break;

                    case "Seeds":
                        food = new Seeds(quantity);
                        break;

                    default:
                        break;
                    }
                    animals.EatFood(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            foreach (var animal in animalsCollect)
            {
                Console.WriteLine(animal);
            }
        }
Пример #9
0
        static void Main(string[] args)
        {
            List <Animal> listAnimals = new List <Animal>();

            while (true)
            {
                string inputCommand = Console.ReadLine();
                if (inputCommand == "End")
                {
                    break;
                }
                else
                {
                    string[] inputAnimalData = inputCommand
                                               .Split(new[] { ' ' })
                                               .ToArray();
                    string   animal         = inputAnimalData[0];
                    string[] eatInformation = Console.ReadLine()
                                              .Split(new[] { ' ' })
                                              .ToArray();
                    switch (animal)
                    {
                    case "Hen":
                        Hen hen = new Hen(inputAnimalData[1], double.Parse(inputAnimalData[2]), int.Parse(inputAnimalData[3]));
                        Console.WriteLine(hen.Speak());
                        Console.Write(hen.AddFood(eatInformation[0], int.Parse(eatInformation[1])));
                        listAnimals.Add(hen);
                        //Console.WriteLine(hen);
                        break;

                    case "Owl":
                        Owl owl = new Owl(inputAnimalData[1], double.Parse(inputAnimalData[2]), int.Parse(inputAnimalData[3]));
                        Console.WriteLine(owl.Speak());
                        Console.Write(owl.AddFood(eatInformation[0], int.Parse(eatInformation[1])));
                        listAnimals.Add(owl);
                        //Console.WriteLine(owl);
                        break;

                    case "Mouse":
                        Mouse mouse = new Mouse(inputAnimalData[1], double.Parse(inputAnimalData[2]), inputAnimalData[3]);
                        Console.WriteLine(mouse.Speak());
                        Console.Write(mouse.AddFood(eatInformation[0], int.Parse(eatInformation[1])));
                        listAnimals.Add(mouse);
                        //Console.WriteLine(mouse);
                        break;

                    case "Dog":
                        Dog dog = new Dog(inputAnimalData[1], double.Parse(inputAnimalData[2]), inputAnimalData[3]);
                        Console.WriteLine(dog.Speak());
                        Console.Write(dog.AddFood(eatInformation[0], int.Parse(eatInformation[1])));
                        listAnimals.Add(dog);
                        //Console.WriteLine(dog);
                        break;

                    case "Cat":
                        Cat cat = new Cat(inputAnimalData[1], double.Parse(inputAnimalData[2]), inputAnimalData[3], inputAnimalData[4]);
                        Console.WriteLine(cat.Speak());
                        Console.Write(cat.AddFood(eatInformation[0], int.Parse(eatInformation[1])));
                        //Console.WriteLine(cat);
                        listAnimals.Add(cat);
                        break;

                    case "Tiger":
                        Tiger tiger = new Tiger(inputAnimalData[1], double.Parse(inputAnimalData[2]), inputAnimalData[3], inputAnimalData[4]);
                        Console.WriteLine(tiger.Speak());
                        Console.Write(tiger.AddFood(eatInformation[0], int.Parse(eatInformation[1])));
                        //Console.WriteLine(tiger);
                        listAnimals.Add(tiger);
                        break;

                    default:
                        break;
                    }
                }
            }

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

            string[] animalInput = Console.ReadLine().Split();
            while (animalInput[0].ToLower() != "end")
            {
                string animalType   = animalInput[0].ToLower();
                string animalName   = animalInput[1];
                double animalWeight = double.Parse(animalInput[2]);

                Animal animal = null;

                if (animalType == "hen")
                {
                    double wingSize = double.Parse(animalInput[3]);

                    animal = new Hen(animalName, animalWeight, wingSize);
                }
                else if (animalType == "owl")
                {
                    double wingSize = double.Parse(animalInput[3]);

                    animal = new Owl(animalName, animalWeight, wingSize);
                }
                else if (animalType == "mouse")
                {
                    string livingRegion = animalInput[3];

                    animal = new Mouse(animalName, animalWeight, livingRegion);
                }
                else if (animalType == "cat")
                {
                    string livingRegion = animalInput[3];
                    string breed        = animalInput[4];

                    animal = new Cat(animalName, animalWeight, livingRegion, breed);
                }
                else if (animalType == "dog")
                {
                    string livingRegion = animalInput[3];

                    animal = new Dog(animalName, animalWeight, livingRegion);
                }
                else if (animalType == "tiger")
                {
                    string livingRegion = animalInput[3];
                    string breed        = animalInput[4];

                    animal = new Tiger(animalName, animalWeight, livingRegion, breed);
                }
                Console.WriteLine(animal.ProduceSound());

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

                string foodType     = foodInput[0].ToLower();
                int    foodQuantity = int.Parse(foodInput[1]);

                Food food = null;

                if (foodType == "vegetable")
                {
                    food = new Vegetable(foodQuantity);
                }
                else if (foodType == "fruit")
                {
                    food = new Fruit(foodQuantity);
                }
                else if (foodType == "meat")
                {
                    food = new Meat(foodQuantity);
                }
                else if (foodType == "seeds")
                {
                    food = new Seeds(foodQuantity);
                }

                animals.Add(animal);

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

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

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] animal = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string[] food   = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

                string foodType     = food[0];
                int    foodQuantity = int.Parse(food[1]);

                if (animal[0] == "Cat" || animal[0] == "Tiger")
                {
                    string type         = animal[0];
                    string name         = animal[1];
                    double weight       = double.Parse(animal[2]);
                    string livingRegion = animal[3];
                    string breed        = animal[4];

                    if (type == "Cat")
                    {
                        Cat cat = new Cat(type, name, weight, livingRegion, breed);
                        cat.FeedMe();

                        if (foodType == "Vegetable" || foodType == "Meat")
                        {
                            cat.Weight   += foodQuantity * 0.30;
                            cat.FoodEaten = foodQuantity;
                        }
                        else
                        {
                            Console.WriteLine($"{type} does not eat {foodType}!");
                        }

                        animals.Add(cat);
                    }
                    else if (type == "Tiger")
                    {
                        Tiger tiger = new Tiger(type, name, weight, livingRegion, breed);
                        tiger.FeedMe();

                        if (foodType == "Meat")
                        {
                            tiger.Weight   += foodQuantity * 1.00;
                            tiger.FoodEaten = foodQuantity;
                        }
                        else
                        {
                            Console.WriteLine($"{type} does not eat {foodType}!");
                        }

                        animals.Add(tiger);
                    }
                }
                else if (animal[0] == "Hen" || animal[0] == "Owl")
                {
                    string type     = animal[0];
                    string name     = animal[1];
                    double weight   = double.Parse(animal[2]);
                    double wingSize = double.Parse(animal[3]);

                    if (type == "Hen")
                    {
                        Hen hen = new Hen(type, name, weight, wingSize);
                        hen.FeedMe();

                        hen.Weight   += foodQuantity * 0.35;
                        hen.FoodEaten = foodQuantity;

                        animals.Add(hen);
                    }
                    else if (type == "Owl")
                    {
                        Owl owl = new Owl(type, name, weight, wingSize);
                        owl.FeedMe();

                        if (foodType == "Meat")
                        {
                            owl.Weight   += foodQuantity * 0.25;
                            owl.FoodEaten = foodQuantity;
                        }
                        else
                        {
                            Console.WriteLine($"{type} does not eat {foodType}!");
                        }

                        animals.Add(owl);
                    }
                }
                else if (animal[0] == "Mouse" || animal[0] == "Dog")
                {
                    string type         = animal[0];
                    string name         = animal[1];
                    double weight       = double.Parse(animal[2]);
                    string livingRegion = animal[3];

                    if (type == "Mouse")
                    {
                        Mouse mouse = new Mouse(type, name, weight, livingRegion);
                        mouse.FeedMe();

                        if (foodType == "Vegetable" || foodType == "Fruit")
                        {
                            mouse.Weight   += foodQuantity * 0.10;
                            mouse.FoodEaten = foodQuantity;
                        }
                        else
                        {
                            Console.WriteLine($"{type} does not eat {foodType}!");
                        }

                        animals.Add(mouse);
                    }
                    else if (type == "Dog")
                    {
                        Dog dog = new Dog(type, name, weight, livingRegion);
                        dog.FeedMe();

                        if (foodType == "Meat")
                        {
                            dog.Weight   += foodQuantity * 0.40;
                            dog.FoodEaten = foodQuantity;
                        }
                        else
                        {
                            Console.WriteLine($"{type} does not eat {foodType}!");
                        }

                        animals.Add(dog);
                    }
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }