Example #1
0
        static void Main()
        {
            TestCreatures();

            Cat[]    catArr  = FillCatArr();
            Dog[]    dogArr  = FillDogArr();
            Frog[]   frogArr = FillFrogArr();
            Kitten[] kitArr  = FillKittenArr();
            Tomcat[] tomArr  = FillTomArr();

            Animal[] animals = { new Cat("cat", 2, true), new Dog("dog", 2, true), new Frog("frog", 2, true) };

            Console.WriteLine(animals[1]);

            decimal averageAgeCats    = Animal.AverageAge(catArr);
            decimal averageAgeDogs    = Animal.AverageAge(dogArr);
            decimal averageAgeFrogs   = Animal.AverageAge(frogArr);
            decimal averageAgeKittens = Animal.AverageAge(kitArr);
            decimal averageAgeTomcats = Animal.AverageAge(tomArr);

            Console.WriteLine("\n***** Average ages *****");
            Console.WriteLine("Cats {0:F2}", averageAgeCats);
            Console.WriteLine("Dogs {0:F2}", averageAgeDogs);
            Console.WriteLine("Frogs {0:F2}", averageAgeFrogs);
            Console.WriteLine("Kittens {0:F2}", averageAgeKittens);
            Console.WriteLine("Tomcats {0:F2}", averageAgeTomcats);
        }
Example #2
0
        static void Main(string[] args)
        {
            Dog[] dogs = new Dog[]
            {
                new Dog(7, "Sharo", false),
                new Dog(9, "Rita", true),
                new Dog(4, "Strela", true)
            };
            Frog[] frogs = new Frog[]
            {
                new Frog(2, "Pesho", false),
                new Frog(1, "Gosho", false)
            };
            Cat[] cats = new Cat[]
            {
                new Cat(4, "Boyko", false),
                new Cat(8, "Klara", true)
            };
            Kitten[] kittens = new Kitten[]
            {
                new Kitten(2, "Lora"),
                new Kitten(1, "Sara")
            };
            Tomcat[] tomcats = new Tomcat[]
            {
                new Tomcat(1, "Tom"),
                new Tomcat(2, "Johnny")
            };

            Console.WriteLine("Dogs average age: {0:F2}", Animal.AverageAge(dogs));
            Console.WriteLine("Frogs average age: {0:F2}", Animal.AverageAge(frogs));
            Console.WriteLine("Cats average age: {0:F2}", Animal.AverageAge(cats));
            Console.WriteLine("Kittens average age: {0:F2}", Animal.AverageAge(kittens));
            Console.WriteLine("Tomcats average age: {0:F2}", Animal.AverageAge(tomcats));

            Console.WriteLine(dogs[0].Bark());
            dogs[1].MakeSound();
            Console.WriteLine(frogs[1].Jump());
            frogs[0].MakeSound();
            Console.WriteLine(cats[0].Sleep());
            cats[1].MakeSound();
            Console.WriteLine(kittens[0].Play());
            kittens[1].MakeSound();
            Console.WriteLine(tomcats[0].Sleep());
            tomcats[1].MakeSound();
        }