Пример #1
0
        private static Animal AddBird(string[] animalArgs)
        {
            var    type     = animalArgs[0];
            var    name     = animalArgs[1];
            var    weight   = double.Parse(animalArgs[2]);
            var    wingSize = double.Parse(animalArgs[3]);
            Animal bird;

            if (type == "Owl")
            {
                bird = new Owl(name, weight, wingSize);
            }
            else
            {
                bird = new Hen(name, weight, wingSize);
            }
            return(bird);
        }
Пример #2
0
        private static Animal CreateAnimal(string[] information)
        {
            string type   = information[0];
            string name   = information[1];
            double weight = double.Parse(information[2]);

            switch (type)
            {
            case "Owl":
                double wingSize = double.Parse(information[3]);
                Animal animal   = new Owl(name, weight, wingSize);
                return(animal);

            case "Hen":
                wingSize = double.Parse(information[3]);
                animal   = new Hen(name, weight, wingSize);
                return(animal);

            case "Mouse":
                string livingRegion = information[3];
                animal = new Mouse(name, weight, livingRegion);
                return(animal);

            case "Dog":
                livingRegion = information[3];
                animal       = new Dog(name, weight, livingRegion);
                return(animal);

            case "Cat":
                livingRegion = information[3];
                string breed = information[4];
                animal = new Cat(name, weight, livingRegion, breed);
                return(animal);

            case "Tiger":
                livingRegion = information[3];
                breed        = information[4];
                animal       = new Tiger(name, weight, livingRegion, breed);
                return(animal);

            default:
                return(null);
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            var animals = new List <Animal>();
            var command = Console.ReadLine();

            while (command != "End")
            {
                var tokens     = command.Split();
                var animalType = tokens[0];
                var name       = tokens[1];
                var weight     = double.Parse(tokens[2]);

                if (Mammals.Contains(animalType))
                {
                    var livingRegion = tokens[3];

                    switch (animalType)
                    {
                    case "Cat":
                        var catBreed = tokens[4];
                        var cat      = new Cat(name, weight, 0, livingRegion, catBreed);
                        animals.Add(cat);
                        FeedAnimal(cat);
                        break;

                    case "Tiger":
                        var tigerBreed = tokens[4];
                        var tiger      = new Tiger(name, weight, 0, livingRegion, tigerBreed);
                        animals.Add(tiger);
                        FeedAnimal(tiger);
                        break;

                    case "Dog":
                        var dog = new Dog(name, weight, 0, livingRegion);
                        animals.Add(dog);
                        FeedAnimal(dog);
                        break;

                    case "Mouse":
                        var mouse = new Mouse(name, weight, 0, livingRegion);
                        animals.Add(mouse);
                        FeedAnimal(mouse);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    var wingSize = double.Parse(tokens[3]);

                    switch (animalType)
                    {
                    case "Owl":
                        var owl = new Owl(name, weight, 0, wingSize);
                        animals.Add(owl);
                        FeedAnimal(owl);
                        break;

                    case "Hen":
                        var hen = new Hen(name, weight, 0, wingSize);
                        animals.Add(hen);
                        FeedAnimal(hen);
                        break;

                    default:
                        break;
                    }
                }

                command = Console.ReadLine();
            }

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