Пример #1
0
        /// <summary>
        /// Creates aniamls for the factory.
        /// </summary>
        /// <param name="type"> The type of animal that will be created.</param>
        /// <param name="name"> The name of the animal.</param>
        /// <param name="age"> The age of the animal.</param>
        /// <param name="weight"> The weight of the animal.</param>
        /// <param name="gender"> The gender of the animal.</param>
        public static Animal CreateAnimal(AnimalType type, string name, int age, double weight, Gender gender)
        {
            Animal result = null;

            switch (type)
            {
            case AnimalType.Chimpanzee:
                result = new Chimpanzee(name, age, weight, gender);

                break;

            case AnimalType.Dingo:
                result = new Dingo(name, age, weight, gender);

                break;

            case AnimalType.Eagle:
                result = new Eagle(name, age, weight, gender);

                break;

            case AnimalType.Hummingbird:
                result = new Hummingbird(name, age, weight, gender);

                break;

            case AnimalType.Kangaroo:
                result = new Kangaroo(name, age, weight, gender);

                break;

            case AnimalType.Ostrich:
                result = new Ostrich(name, age, weight, gender);

                break;

            case AnimalType.Platypus:
                result = new Platypus(name, age, weight, gender);

                break;

            case AnimalType.Shark:
                result = new Shark(name, age, weight, gender);

                break;

            case AnimalType.Squirrel:
                result = new Squirrel(name, age, weight, gender);

                break;

            default:
                break;
            }

            return(result);
        }
Пример #2
0
        static void Main(string[] args)
        {
            Dog dog = new Dog();
            Cat cat = new Cat();
            Crocodile crocodile = new Crocodile();
            Shark shark = new Shark();
            Owl owl = new Owl();

            List<Animal> animals = new List<Animal>();
            animals.Add(dog);
            animals.Add(cat);
            animals.Add(crocodile);
            animals.Add(shark);
            animals.Add(owl);

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.Eat());
            }
            Console.WriteLine(dog.Greet());
        }
Пример #3
0
        static void Main(string[] args)
        {
            Mammals m = new Mammals();
            Console.WriteLine(m.Move());
            Console.WriteLine(m.Greet());
            m = new Cat();
            Console.WriteLine(m.Move());
            Console.WriteLine(m.Greet());
            m = new Dog();
            Console.WriteLine(m.Move());
            Console.WriteLine(m.Greet());

            Console.WriteLine();

            Reptiles r = new Reptiles();
            Console.WriteLine(r.Move());
            Console.WriteLine(r.Temperature());
            r = new Crocodile();
            Console.WriteLine(r.Move());
            Console.WriteLine(r.Temperature());

            Console.WriteLine();

            Birds b = new Birds();
            Console.WriteLine(b.Move());
            Console.WriteLine(b.MakeNest());
            b = new Owl();
            Console.WriteLine(b.Move());
            Console.WriteLine(b.MakeNest());

            Console.WriteLine();

            Fish f = new Fish();
            Console.WriteLine(f.Move());
            f = new Shark();
            Console.WriteLine(f.Move());

            Console.ReadKey();
        }
Пример #4
0
        static void Main()
        {
            // Animal A = new Animal();

            Shark <int> S = new Shark <int>();

            S.Size        = 6;
            S.Name        = "Hammerhead";
            S.EatingHabit = "Carnivore";

            Console.WriteLine(S.GetName());
            Console.WriteLine(S.GetClassification());
            Console.WriteLine(S.GetHabitat());
            Console.WriteLine(S.GetEatingHabits());
            Console.WriteLine(S.Size);

            Shark <string> S2 = new Shark <string>();

            S2.Size        = "0.6096 - 1.524 meters";
            S2.Name        = "Bonnethead";
            S2.EatingHabit = "Omnivore";

            Console.WriteLine(S2.GetName());
            Console.WriteLine(S2.GetClassification());
            Console.WriteLine(S2.GetHabitat());
            Console.WriteLine(S2.GetEatingHabits());
            Console.WriteLine(S2.Size);

            Dog D = new Dog();

            D.Name = "Pekingese";
            //D.Size = 0.4; - inaccessible
            D.SetSize(0.4);

            Console.WriteLine(D.GetName());
            Console.WriteLine(D.GetClassification());
            Console.WriteLine(D.GetEatingHabits());
        }
Пример #5
0
        /// <summary>
        /// Creates an animal.
        /// </summary>
        /// <param name="type">The type of animal.</param>
        /// <param name="name">The name of the animal.</param>
        /// <param name="age">The age of the animal.</param>
        /// <param name="weight">The weight of the animal.</param>
        /// <param name="gender">The gender of the animal.</param>
        /// <returns>Returns an animal.</returns>
        public static Animal CreateAnimal(AnimalType type, string name, int age, double weight, Gender gender)
        {
            Animal animal = null;

            switch (type)
            {
            case AnimalType.Chimpanzee:

                // Create Chewy the chimpanzee.
                animal = new Chimpanzee(name, age, weight, gender);

                break;

            case AnimalType.Dingo:

                // Create Dolly the dingo.
                animal = new Dingo(name, age, weight, gender);

                // Create Dixie the dingo.
                animal = new Dingo(name, age, weight, gender);

                break;

            case AnimalType.Eagle:
                // Create Edgar the eagle..
                animal = new Eagle(name, age, weight, gender);

                break;

            case AnimalType.Hummingbird:
                // Create Harold.
                animal = new Hummingbird(name, age, weight, gender);

                break;

            case AnimalType.Kangaroo:
                // Create Khan the kangaroo.
                animal = new Kangaroo(name, age, weight, gender);

                break;

            case AnimalType.Ostrich:
                // Create Ozzie the ostrich.
                animal = new Ostrich(name, age, weight, gender);

                break;

            case AnimalType.Platypus:
                // Create Patty.
                animal = new Platypus(name, age, weight, gender);

                break;

            case AnimalType.Shark:
                // Creates Sasha the shark.
                animal = new Shark(name, age, weight, gender);

                break;

            case AnimalType.Squirrel:
                // Create Sonny the squirrel.
                animal = new Squirrel(name, age, weight, gender);

                break;
            }

            return(animal);
        }