示例#1
0
文件: Program.cs 项目: dakers2/Zoo
        static void Main(string[] args)
        {
            Tiger t = new Tiger();

            t.Birthdate = new DateTime(2011, 8, 24);
            t.HairColor = "Orange, White, Black";
            t.Name      = "Tony";
            t.IsAlive   = true;
            t.Jump(20);

            t.SetBirthPlace("Chicago");
            t.SetCurrentZoo("Brookfield");


            Platypus p = new Platypus();

            p.Name = "Patty";
            p.LayAnEgg();

            // with interfaces, you can never create new instances of that object
            // e.g. you can't do this:
            // ILayEggs p = new ILayEggs;

            //alternate way to write this:
            //ILayEggs p = new Platypus();
            // but you need to cast the type to access all properties of Platypus class
            //((Platypus)p).Name = "Patty";
            //p.LayAnEgg();

            Console.ReadLine();
        }
示例#2
0
        static void MammalCalls()
        {
            Elephant dumbo = new Elephant()
            {
                Name = "Dumbo"
            };

            Platypus ducky = new Platypus()
            {
                Name = "Ducky"
            };

            Console.WriteLine($"{dumbo.Name} sounds like this : {dumbo.MakeNoise()} and has {dumbo.NumberOfEyes} eyes");
            Console.WriteLine($" platypus does this: {ducky.LayEgg()}");
            ducky.ProduceVenom();
        }
示例#3
0
        static void Main(string[] args)
        {
            // Brown bear instance
            BrownBear yogi = new BrownBear();

            yogi.AnimalCount++;
            Console.WriteLine($"{yogi.Speak()} I'm a brown bear!");
            Console.WriteLine($"There are {yogi.AnimalCount} brown bears in the Zoo.");
            Console.WriteLine($"Is the brown bear a warm blooded animal? {yogi.IsWarmBlooded}");
            Console.WriteLine(yogi.BearHug());
            Console.WriteLine(yogi.GuestFeedAnimal());

            Console.WriteLine();

            // Tiger instance
            Tiger tony = new Tiger();

            Console.WriteLine(tony.Feed());
            Console.WriteLine(tony.StaffFeedAnimal());
            Console.WriteLine(tony.Swim());

            Console.WriteLine();

            // Black bear instance
            BlackBear baloo = new BlackBear();

            Console.WriteLine($"{baloo.Speak()} I'm a black bear!");
            Console.WriteLine(baloo.Swim());

            Console.WriteLine();

            // Platypus instance
            Platypus abomination = new Platypus();

            Console.WriteLine($"I'm a platypus! Am I venomous? {abomination.IsVenomous}");
            Console.WriteLine(abomination.Feed());

            Console.WriteLine();

            // Alligator instance
            Alligator seeYaLater = new Alligator();

            Console.WriteLine($"There are {seeYaLater.AnimalCount} alligators in the zoo.");
            Console.WriteLine($"Do gators lay eggs? {seeYaLater.LaysEggs}");
            Console.WriteLine(seeYaLater.Feed());

            Console.WriteLine();

            // Sea Turtle instance
            SeaTurtle timmy = new SeaTurtle();

            Console.WriteLine($"I'm a sea turtle! Do I lay eggs? {timmy.LaysEggs}");
            Console.WriteLine(timmy.Swim());

            Console.WriteLine();

            // Box Turtle instance
            BoxTurtle michaelangelo = new BoxTurtle();

            Console.WriteLine($"I'm a box turtle! Can I swim? {michaelangelo.LivesInWater}");
            Console.WriteLine(michaelangelo.Feed());

            Console.WriteLine();

            // King Cobra instance
            KingCobra commander = new KingCobra();

            Console.WriteLine($"I'm a king cobra! Am I venomous? {commander.IsVenomous}");
            Console.WriteLine($"Do I lay eggs? {commander.LaysEggs}");
            Console.WriteLine(commander.Feed());
        }