Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int[] animalAges = new int[5];

            Animal frog = new Frog("Froggy", 1, "male");

            frog.ProduceSound();
            animalAges[0] = frog.Age;

            Animal kitten = new Kitten("Kitty", 4);

            kitten.ProduceSound();
            animalAges[1] = kitten.Age;

            Animal dog = new Dog("Sharo", 10, "male");

            dog.ProduceSound();
            animalAges[2] = dog.Age;

            Animal tomcat = new Tomcat("Tiger", 6);

            tomcat.ProduceSound();
            animalAges[3] = tomcat.Age;

            Animal cat = new Cat("Fluffy", 3, "female");

            cat.ProduceSound();
            animalAges[4] = cat.Age;

            Animal cat2 = new Cat("Maui Mauski", 18, "male");

            cat2.ProduceSound();

            Console.WriteLine("Average: {0}", calcAverage(animalAges));
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var dog  = new Dog("Sharo", 3, Gender.Male);
            var dog1 = new Dog("Pumiar", 9, Gender.Male);

            dog.ProduceSound();
            var frog  = new Frog("Jabcho", 2, Gender.Male);
            var frog1 = new Frog("Cermit", 4, Gender.Male);

            frog.ProduceSound();
            var tomcat  = new Tomcat("Tom", 5);
            var tomcat1 = new Tomcat("Garfield", 1);

            tomcat.ProduceSound();
            var kitten  = new Kitten("Kitty", 2);
            var kitten1 = new Kitten("Sarra", 7);

            kitten.ProduceSound();

            Animal[] animals = { dog, dog1, frog, frog1, tomcat, tomcat1, kitten, kitten1 };

            double dogsAverageAge    = animals.Where(a => a is Dog).Average(a => a.Age);
            double frogsAverageAge   = animals.Where(a => a is Frog).Average(a => a.Age);
            double kittensAverageAge = animals.Where(a => a is Kitten).Average(a => a.Age);
            double tomcatsAverageAge = animals.Where(a => a is Tomcat).Average(a => a.Age);

            Console.WriteLine("Dogs average age is {0:F2}", dogsAverageAge);
            Console.WriteLine("Frogs average age is {0:F2}", frogsAverageAge);
            Console.WriteLine("Tomcats average age is {0:F2}", tomcatsAverageAge);
            Console.WriteLine("Kittens average age is {0:F2}", kittensAverageAge);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            int[] animalAges = new int[5];

            Animal frog = new Frog("Froggy", 1, "male");
            frog.ProduceSound();
            animalAges[0] = frog.Age;

            Animal kitten = new Kitten("Kitty", 4);
            kitten.ProduceSound();
            animalAges[1] = kitten.Age;

            Animal dog = new Dog("Sharo", 10, "male");
            dog.ProduceSound();
            animalAges[2] = dog.Age;

            Animal tomcat = new Tomcat("Tiger", 6);
            tomcat.ProduceSound();
            animalAges[3] = tomcat.Age;

            Animal cat = new Cat("Fluffy", 3, "female");
            cat.ProduceSound();
            animalAges[4] = cat.Age;

            Animal cat2 = new Cat("Maui Mauski", 18, "male");
            cat2.ProduceSound();

            Console.WriteLine("Average: {0}",  calcAverage(animalAges));    
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                Frog Goshko = new Frog("Goshko", 10, "male");
                Frog Dimitrur = new Frog("Dimitur",6, "male");
                Frog Minka = new Frog("Minka", 3, "female");

                Dog Rex = new Dog("Rex", 1, "male");
                Dog Hunter = new Dog("Hunter", 5, "male");
                Dog Blondie = new Dog("Blondie",3,"female");

                Kitten Puxy = new Kitten ("Puxy" , 2);
                Kitten Dazzy = new Kitten("Dazzy",5);
                Kitten Tuffy = new Kitten("Tuffy", 4);

                TomCat Tom = new TomCat("Tom", 4);
                TomCat Djeramaia = new TomCat("Djeramaia", 1);
                TomCat Virgin = new TomCat("Virgin",7);

                IList<Animal> animals = new List<Animal>
                {
                    Goshko,Dimitrur,Minka,Rex,Hunter,Blondie,Puxy,Dazzy,Tuffy,Tom,Djeramaia,Virgin
                };
                Goshko.ProduceSound();
                Rex.ProduceSound();
                Puxy.ProduceSound();
                Tom.ProduceSound();

                double catsAverageAge = animals
                    .Where(animal => animal is Cat)
                    .Average(cat => cat.Age);
                double dogsAverageAge = animals
                                    .Where(animal => animal is Dog)
                                    .Average(dog => dog.Age);

                double frogsAverageAge = animals
                    .Where(animal => animal is Frog)
                    .Average(frog => frog.Age);

                Console.WriteLine("Frogs average age is: {0:F2}", frogsAverageAge);
                Console.WriteLine("Dogs average age is: {0:F2}", dogsAverageAge);
                Console.WriteLine("Cats average age is: {0:F2}", catsAverageAge);

            }
            catch (ArgumentOutOfRangeException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentNullException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            try
            {
                Frog Goshko   = new Frog("Goshko", 10, "male");
                Frog Dimitrur = new Frog("Dimitur", 6, "male");
                Frog Minka    = new Frog("Minka", 3, "female");

                Dog Rex     = new Dog("Rex", 1, "male");
                Dog Hunter  = new Dog("Hunter", 5, "male");
                Dog Blondie = new Dog("Blondie", 3, "female");

                Kitten Puxy  = new Kitten("Puxy", 2);
                Kitten Dazzy = new Kitten("Dazzy", 5);
                Kitten Tuffy = new Kitten("Tuffy", 4);

                TomCat Tom       = new TomCat("Tom", 4);
                TomCat Djeramaia = new TomCat("Djeramaia", 1);
                TomCat Virgin    = new TomCat("Virgin", 7);

                IList <Animal> animals = new List <Animal>
                {
                    Goshko, Dimitrur, Minka, Rex, Hunter, Blondie, Puxy, Dazzy, Tuffy, Tom, Djeramaia, Virgin
                };
                Goshko.ProduceSound();
                Rex.ProduceSound();
                Puxy.ProduceSound();
                Tom.ProduceSound();

                double catsAverageAge = animals
                                        .Where(animal => animal is Cat)
                                        .Average(cat => cat.Age);
                double dogsAverageAge = animals
                                        .Where(animal => animal is Dog)
                                        .Average(dog => dog.Age);

                double frogsAverageAge = animals
                                         .Where(animal => animal is Frog)
                                         .Average(frog => frog.Age);

                Console.WriteLine("Frogs average age is: {0:F2}", frogsAverageAge);
                Console.WriteLine("Dogs average age is: {0:F2}", dogsAverageAge);
                Console.WriteLine("Cats average age is: {0:F2}", catsAverageAge);
            }
            catch (ArgumentOutOfRangeException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentNullException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }
        }