示例#1
0
 /// <summary>
 /// Creates an array of objects that represent each class that inherits from Primate
 /// </summary>
 /// <returns>Array of classes that inherit from Primate</returns>
 public static Primate[] CreatePrimates()
 {
     Primate[] primates = new Primate[3];
     primates[0] = new Lemur();
     primates[1] = new Chimpanzee();
     primates[2] = new Proboscis();
     return(primates);
 }
示例#2
0
        public static bool ChimpIsMammal()
        {
            Chimpanzee c = new Chimpanzee();

            if (c is Mammal)
            {
                return(true);
            }
            return(false);
        }
示例#3
0
        //People think that monkeys and apes are the same thing. Isn't!
        //While monkeys have tails and don't have appendix, the apes are the opposite.
        //So.. we've a problem with de Liskov principle, if a chimpanzee is not a monkey, the chimpanzee class cannot be substituted
        //by monkey class
        static void Main(string[] args)
        {
            Monkey monkey = new Monkey();

            monkey.ShowTail();

            Monkey chimpanzee = new Chimpanzee();

            chimpanzee.ShowTail();
            Console.ReadLine();
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Beagle beagle = new Beagle();

            Console.WriteLine(beagle.IsHunter);
            Console.WriteLine(beagle.DoTrick());
            Console.WriteLine(beagle.EatFood());
            Console.WriteLine(beagle.FormsGroup());
            Console.WriteLine(beagle.MakesBabies());
            Console.WriteLine(beagle.LearnTrick());

            Husky husky = new Husky();

            Console.WriteLine(husky.LovesSnow);
            Console.WriteLine(husky.DoTrick());
            Console.WriteLine(husky.EatFood());
            Console.WriteLine(husky.FormsGroup());
            Console.WriteLine(husky.MakesBabies());
            Console.WriteLine(husky.LearnTrick());

            Chimpanzee chimp = new Chimpanzee();

            Console.WriteLine(chimp.HasHeart);
            Console.WriteLine(chimp.NumberOfLegs);
            Console.WriteLine(chimp.EatFood());
            Console.WriteLine(chimp.FormsGroup());
            Console.WriteLine(chimp.MakesBabies());
            Console.WriteLine(beagle.MakeSound());

            Dolphin dolphin = new Dolphin();

            Console.WriteLine(dolphin.HasHeart);
            Console.WriteLine(dolphin.BreathesAir);
            Console.WriteLine(dolphin.HasScales);
            Console.WriteLine(dolphin.DoTrick());
            Console.WriteLine(dolphin.EatFood());
            Console.WriteLine(dolphin.EatsHumans());
            Console.WriteLine(dolphin.MakesBabies());
            Console.WriteLine(dolphin.MakeSound());

            Shark shark = new Shark();

            Console.WriteLine(shark.HasHeart);
            Console.WriteLine(shark.BreathesAir);
            Console.WriteLine(shark.HasScales);
            Console.WriteLine(shark.EatFood());
            Console.WriteLine(shark.EatsHumans());
            Console.WriteLine(shark.MakeSound());
        }
示例#5
0
        static void Main(string[] args)
        {
            Primate chimpanzee = new Chimpanzee();

            Console.WriteLine(chimpanzee.ToString());

            Primate monkey = new Monkey();

            Console.WriteLine(monkey.ToString());

            Monkey monkey2 = new Monkey();

            monkey2.ShowTail();

            Console.ReadLine();
        }
示例#6
0
        static void Main(string[] args)
        {
            IHuman human1 = new Man();
            IHuman human2 = new Woman();

            IMonkey monkey1      = new Baboon();
            IMonkey monkey2      = new Chimpanzee();
            IMonkey monkey3      = new Gorilla();
            IMonkey humanMonkey1 = new HumanAdapter(human1);
            IMonkey humanMonkey2 = new HumanAdapter(human2);

            monkey1.Screech();
            monkey2.Screech();
            monkey3.Screech();
            humanMonkey1.Screech();
            humanMonkey2.Screech();
        }
示例#7
0
        /// <summary>
        /// Creates an instance of the zoo class and configures it as the Como Zoo.
        /// </summary>
        private void CreateComoZoo()
        {
            // Create an instance of the Zoo class.
            this.comoZoo = new Zoo("Como Zoo", 1000, 4, 0.75m, 15.00m, 3640.25m, new Employee("Sam", 42), new Employee("Flora", 98), 3);

            // Add money to the animal snack machine.
            this.comoZoo.AnimalSnackMachine.AddMoney(42.75m);

            // Define an animal variable.
            Animal animal;

            // Create a new Dingo and add him to the list of animals.
            animal = new Dingo("Dolly", 4, 35.3);

            animal.MakePregnant();

            this.comoZoo.AddAnimal(animal);

            // Create a new Dingo and add him to the list of animals.
            animal = new Dingo("Dixie", 3, 33.8);

            animal.MakePregnant();

            this.comoZoo.AddAnimal(animal);

            // Create a new platypus and add him to the list of animals.
            animal = new Platypus("Patty", 2, 15.5);

            animal.MakePregnant();

            this.comoZoo.AddAnimal(animal);

            // Create a new Hummingbird and add him to the list of animals.
            animal = new Hummingbird("Harold", 1, 0.5);

            this.comoZoo.AddAnimal(animal);

            // Create a new chimp and add him to the list of animals.
            animal = new Chimpanzee("Noah", 12, 500);

            this.comoZoo.AddAnimal(animal);

            // Create a new eagle and add him to the list of animals.
            animal = new Eagle("Tracy", 300, 10);

            this.comoZoo.AddAnimal(animal);

            // Create a new kangaroo and add him to the list of animals.
            animal = new Kangaroo("Jeff", 25, 30);

            this.comoZoo.AddAnimal(animal);

            // Create a new ostrich and add him to the list of animals.
            animal = new Ostrich("Jake", 40, 200);

            this.comoZoo.AddAnimal(animal);

            // Create a new shark and add him to the list of animals.
            animal = new Shark("Max", 23, 185);

            this.comoZoo.AddAnimal(animal);

            // Create a new squirrel and them to the list.
            animal = new Squirrel("Matt", 21, 200);

            this.comoZoo.AddAnimal(animal);

            // Create a guest.
            Guest guest = new Guest("Greg", 44, 150.35m, "Brown");

            // Add the guest and sell the ticket to the guest.
            this.comoZoo.AddGuest(guest, this.comoZoo.SellTicket(guest));

            // Create a guest.
            guest = new Guest("Darla", 11, 25.25m, "Salmon");

            // Add the guest and sell the ticket to the guest.
            this.comoZoo.AddGuest(guest, this.comoZoo.SellTicket(guest));
        }
示例#8
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to my zoo!\n");
            Console.WriteLine("My zoo has an abstract base class called Mammal.\nMammals" +
                              " have 1) an abstract name and 2) an abstract age, and can 1) eat (abstract) and 2) make a sound (virtual).\n");

            Console.WriteLine("\n\nHit <ENTER> to continue.");
            Console.ReadLine();

            //Show info about Bears and demo different Bear subclasses
            Console.WriteLine("The class 'Bear' inherits from Mammal and overrides all properties and methods. Bear additionally" +
                              " adds a virtual property called ClawLength and an abstract method called Hunts().\n");
            Console.WriteLine("There are three Bear descendent classes: Panda, Grizzly, and PolarBear.");
            Console.WriteLine("Pandas, Grizzlies, and PolarBears override all properties and methods of Bear EXCEPT for: ClawLength, Age, and Sound.");
            Bear[] myBears = CreateBears();

            Console.WriteLine("\n\nHit <ENTER> to see a demonstration of each class that inherits from Bear.");
            Console.ReadLine();
            Console.WriteLine("Here's a demonstration of each bear type\n");
            ShowBears(myBears);
            Console.WriteLine("\n\nHit <ENTER> to continue.");
            Console.ReadLine();


            //Instantiate Primates and return collection of primates
            Console.WriteLine("The class 'Primate' inherits from Mammal and overrides all properties and methods. Primate additionally" +
                              " adds a virtual property called HasTail and an virtual method called Hangs().\n");
            Console.WriteLine("There are three Primate descendent classes: Lemur, Chimpanzee, and Proboscis.");
            Console.WriteLine("Lemurs and Proboscii override Name, Eats(), Sound(), while Chimpanzees additionally override HasTail. ");
            Primate[] myPrimates = CreatePrimates();
            Console.WriteLine("\n\nHit <ENTER> to see a demonstration of each class that inherits from Primate.");
            Console.ReadLine();
            Console.WriteLine("Here's a demonstration of each primate type\n");
            ShowPrimates(myPrimates);
            Console.WriteLine("\n\nHit <ENTER> to continue.");
            Console.ReadLine();

            //Show RingTailed
            Console.WriteLine("Additionally, the class RingTailed inherits from Lemur and adds a method called SpendsTime()");
            RingTailed ringTailedLemur = new RingTailed();

            Console.WriteLine($"Name: {ringTailedLemur.Name}");
            Console.WriteLine($"Age: {ringTailedLemur.Age}");
            Console.WriteLine($"Has tail? {ringTailedLemur.HasTail}");
            Console.WriteLine($"Eats: {ringTailedLemur.Eats()}");
            Console.WriteLine($"Sound: {ringTailedLemur.Sound()}");
            Console.WriteLine($"Hangs: {ringTailedLemur.Hangs()}");
            Console.WriteLine($"Spends time: {ringTailedLemur.SpendsTime()}");
            Console.WriteLine();

            //Show Interface Implementation
            Console.WriteLine("Finally, there are two interfaces: ICanSwim and ICanGroom.");
            Console.WriteLine("Chimpanzee implements both, while PolarBear implements ICanSwim");
            Console.WriteLine("\n\nHit <ENTER> to see a demonstration.");
            Console.ReadLine();
            PolarBear  pb = new PolarBear();
            Chimpanzee c  = new Chimpanzee();

            Console.WriteLine($"calling PolarBear.Swim(): {pb.Swim()}");
            Console.WriteLine($"calling PolarBear.DryOff(): {pb.DryOff()}");
            Console.WriteLine($"calling Chimpanzee.Swim(): {c.Swim()}");
            Console.WriteLine($"calling Chimpanzee.DryOff(): {c.DryOff()}");
            Console.WriteLine($"calling Chimpanzee.Groom(): {c.Groom()}");
            Console.WriteLine($"calling Chimpanzee.EatFoundBug: {c.EatFoundBug()}");
        }
示例#9
0
        public static string ChimpSwims()
        {
            Chimpanzee c = new Chimpanzee();

            return(c.Swim());
        }
示例#10
0
        public static string ChimpGrooms()
        {
            Chimpanzee c = new Chimpanzee();

            return(c.Groom());
        }
示例#11
0
        public static string ChimpSound()
        {
            Chimpanzee c = new Chimpanzee();

            return(c.Sound());
        }
示例#12
0
        public static bool DoesChimpHaveTail()
        {
            Chimpanzee c = new Chimpanzee();

            return(c.HasTail);
        }
示例#13
0
    public override Species Reproduction(Species species)
    {
        Chimpanzee monkey = new Chimpanzee();

        return(monkey);
    }