Example #1
0
        public void Run()
        {
            string command = "";

            while ((command = Console.ReadLine()) != "End")
            {
                string[] animalInfo = command.Split();
                string[] foodInfo   = Console.ReadLine().Split();

                string animalType = animalInfo[0].ToLower();
                string name       = animalInfo[1];
                double weight     = double.Parse(animalInfo[2]);

                if (animalType == "cat" || animalType == "tiger")
                {
                    string livingRegion = animalInfo[3];
                    string breed        = animalInfo[4];
                    animal = (IAnimal)felineFactory.CreateFeline(animalType, name, weight, livingRegion, breed);
                }
                else if (animalType == "owl" || animalType == "hen")
                {
                    double wingSize = double.Parse(animalInfo[3]);
                    animal = (IAnimal)birdFactory.CreateBird(animalType, name, weight, wingSize);
                }
                else if (animalType == "mouse" || animalType == "dog")
                {
                    string livingRegion = animalInfo[3];
                    animal = (IAnimal)mammalFactory.CreateMammal(animalType, name, weight, livingRegion);
                }

                animals.Add(animal);
                animal.ProduceSound();

                try
                {
                    string foodType = foodInfo[0];
                    double quantity = double.Parse(foodInfo[1]);

                    IFood food = foodFactory.CreateFood(foodType, quantity);
                    animal.Eat(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (var animal in this.animals)
            {
                Console.WriteLine(animal);
            }
        }
Example #2
0
        public void Run()
        {
            string input = string.Empty;

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

                string animalType   = animalInfo[0];
                string animalName   = animalInfo[1];
                double animalWeight = double.Parse(animalInfo[2]);



                if (animalType == "Hen" || animalType == "Owl")
                {
                    double wingSize = double.Parse(animalInfo[3]);

                    animal = birdFactory.CreateBird(animalType, animalName, animalWeight, wingSize);
                }
                else if (animalType == "Dog" || animalType == "Mouse")
                {
                    string livingregion = animalInfo[3];
                    animal = mammalFactory.CreateMammal(animalType, animalName, animalWeight, livingregion);
                }
                else if (animalType == "Cat" || animalType == "Tiger")
                {
                    string livingregion = animalInfo[3];
                    string breed        = animalInfo[4];

                    animal = felineFactory.CreateFeline(animalType, animalName, animalWeight, livingregion, breed);
                }

                string[] foodInfo     = Console.ReadLine().Split();
                string   foodType     = foodInfo[0];
                int      foodQuantity = int.Parse(foodInfo[1]);

                Food food = foodFactory.CreateFood(foodType, foodQuantity);

                animal.ProduceSound();
                animal.Eat(food);
                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Example #3
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (input != "End")
            {
                string[] animalArguments = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   typeAnimal      = animalArguments[0].ToLower();
                string   name            = animalArguments[1];
                double   weight          = double.Parse(animalArguments[2]);

                if (typeAnimal == "hen" || typeAnimal == "owl")
                {
                    double wingSize = double.Parse(animalArguments[3]);
                    animal = birdFactory.CreateBird(typeAnimal, name, weight, wingSize);
                }
                else if (typeAnimal == "mouse" || typeAnimal == "dog")
                {
                    string livingRegion = animalArguments[3];
                    animal = mammalFactory.CreateMammal(typeAnimal, name, weight, livingRegion);
                }
                else if (typeAnimal == "cat" || typeAnimal == "tiger")
                {
                    string livingRegion = animalArguments[3];
                    string breed        = animalArguments[4];
                    animal = felineFactory.CreateFeline(typeAnimal, name, weight, livingRegion, breed);
                }

                animal.ProduceSound();
                string[] foodArguments = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   typeFood      = foodArguments[0];
                int      quantity      = int.Parse(foodArguments[1]);
                var      food          = foodFactory.CreateFood(typeFood, quantity);

                animal.Eat(food);
                this.animals.Add(animal);

                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
Example #4
0
        private void GetAnimal(string[] animalInfo, string typeOfAnimal, string name, double weight)
        {
            if (typeOfAnimal.Equals("Hen") || typeOfAnimal.Equals("Owl"))
            {
                double wingSize = double.Parse(animalInfo[3]);

                animal = birdFactory.CreateBird(typeOfAnimal, name, weight, wingSize);
            }
            else if (typeOfAnimal.Equals("Mouse") || typeOfAnimal.Equals("Dog"))
            {
                string livingRegion = animalInfo[3];

                animal = mammalFactory.CreateMamal(typeOfAnimal, name, weight, livingRegion);
            }
            else if (typeOfAnimal.Equals("Cat") || typeOfAnimal.Equals("Tiger"))
            {
                string livingRegion = animalInfo[3];
                string breed        = animalInfo[4];

                animal = felineFactory.CreateFeline(typeOfAnimal, name, weight, livingRegion, breed);
            }
        }
Example #5
0
        public void Run()
        {
            string input  = Console.ReadLine();
            Animal animal = null;

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

                try
                {
                    if (type.Equals("Cat") || type.Equals("Tiger"))
                    {
                        string livingRegion = inputArguments[3];
                        string breed        = inputArguments[4];

                        animal = felineFactory.CreateFeline(type, name, weight, livingRegion, breed);
                    }
                    else if (type.Equals("Dog") || type.Equals("Mouse"))
                    {
                        string livingRegion = inputArguments[3];

                        animal = mammalsFactory.CreateMamamls(type, name, weight, livingRegion);
                    }
                    else if (type.Equals("Owl") || type.Equals("Hen"))
                    {
                        double wingSize = double.Parse(inputArguments[3]);

                        animal = birdFactory.CreateBirds(type, name, weight, wingSize);
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                string   secondInput  = Console.ReadLine();
                string[] secondInputs = secondInput.Split();
                var      foodType     = foodfactory.CreateFoods(secondInputs[0], int.Parse(secondInputs[1]));
                animal.ProduceSound();
                try
                {
                    animal.Eat(foodType);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animals.Add(animal);

                input = Console.ReadLine();
            }

            foreach (var currentAnimal in animals)
            {
                Console.WriteLine(currentAnimal);
            }
        }
        public void Run()
        {
            BirdFactory   birdFactory   = new BirdFactory();
            MammalFactory mammalFactory = new MammalFactory();
            FelineFactory felineFactory = new FelineFactory();
            FoodFactory   foodFactory   = new FoodFactory();

            List <Animal> animals = new List <Animal>();

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

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

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

                string animalType   = currentAnimal[0];
                string animalName   = currentAnimal[1];
                double animalWeight = double.Parse(currentAnimal[2]);

                string foodType     = currentFood[0];
                int    foodQuantity = int.Parse(currentFood[1]);
                Food   food         = foodFactory.CreateFood(foodType, foodQuantity);

                try
                {
                    if (animalType == "Hen" || animalType == "Owl")
                    {
                        double wingSize = double.Parse(currentAnimal[3]);
                        Animal animal   = birdFactory.CreateBird(animalType, animalName, animalWeight, wingSize);

                        animal.ProduceSound();
                        animals.Add(animal);
                        animal.Eat(food);
                    }
                    else if (animalType == "Mouse" || animalType == "Dog")
                    {
                        string livingRegion = currentAnimal[3];
                        Animal animal       = mammalFactory.CreateMammal(animalType, animalName, animalWeight, livingRegion);

                        animal.ProduceSound();
                        animals.Add(animal);
                        animal.Eat(food);
                    }
                    else if (animalType == "Cat" || animalType == "Tiger")
                    {
                        string livingRegion = currentAnimal[3];
                        string breed        = currentAnimal[4];
                        Animal animal       = felineFactory.CreateFeline(animalType, animalName, animalWeight, livingRegion, breed);

                        animal.ProduceSound();
                        animals.Add(animal);
                        animal.Eat(food);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

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