Exemple #1
0
        static void Main(string[] args)
        {
            Platypus ornitorinc           = new Platypus("Ornitorinc", 20, 4, 2);
            WildDuck rata                 = new WildDuck("Donald", 20, 6, 35, 500);
            Piranha  piranha              = new Piranha("Nemo", 25, 250);
            AhkistrodonPiscivorus mocasin = new AhkistrodonPiscivorus("Boa", 20, 15, "frogs");
            Ladybug gargarita             = new Ladybug("Gargarita", 0.5, 15, Ladybug.LadybugColor.Black, 12);

            Animal[] animals = { ornitorinc, rata, piranha, mocasin, gargarita };
            Console.WriteLine("\t\tInitialy\n");
            foreach (Animal a in animals)
            {
                Console.WriteLine($"{a}\n");
            }

            Console.WriteLine("Press enter to continue");
            Console.ReadLine();

            ornitorinc.MakeAnEgg();
            ornitorinc.MakeAnEgg();
            ornitorinc.BreakAnEgg();
            ornitorinc.Hatch();

            rata.GainWeight(45);
            piranha.Grow(10);
            mocasin.AddFavouriteFood(" trout triton");
            mocasin.RemoveFavouriteFood("frogs");

            Console.WriteLine("\t\tAfter the changes\n");
            foreach (Animal a in animals)
            {
                Console.WriteLine($"{a}\n");
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Eagle eagle = new Eagle("Val", AnimalCategories.bird);

            Console.WriteLine(eagle);
            eagle.Swim();
            eagle.Fly();
            eagle.Move();
            eagle.Walk();

            Console.WriteLine("--------------------------------------------");

            Platypus platypus = new Platypus("Orni", AnimalCategories.mammal);

            Console.WriteLine(platypus);
            platypus.Move();
            platypus.Swim();
            platypus.Walk();

            Console.WriteLine("---------------------------------------------");


            WildDuck wildDuck = new WildDuck("Donald", AnimalCategories.bird);

            Console.WriteLine(wildDuck);
            wildDuck.Fly();
            wildDuck.Move();
            wildDuck.Swim();
            wildDuck.Walk();


            Console.WriteLine("----------------------------------------------");

            Crocodile aligator = new Crocodile("Aligator", AnimalCategories.reptile);

            Console.WriteLine(aligator);
            aligator.Crawl();
            aligator.Move();
            aligator.Swim();
            aligator.Walk();
        }
Exemple #4
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);
        }