Exemple #1
0
        public static string RTName()
        {
            RingTailed rt = new RingTailed();

            return(rt.Name);
        }
Exemple #2
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()}");
        }
Exemple #3
0
        public static string RTSpendsTime()
        {
            RingTailed rt = new RingTailed();

            return(rt.SpendsTime());
        }