Exemplo n.º 1
3
        public static void Main()
        {
            Cat[] cats = new Cat[]
            {
                new Cat("Pussi", 3, false),
                new Cat("Pesho", 6, true),
                new Cat("Ginka", 7, false),
            };
            Dog[] dogs = new Dog[]
            {
                new Dog("Misho", 5, true, "Ovcharka"),
                new Dog("Bull", 6, true, "Buldog"),
                new Dog("Rocko", 7, true, "Sharpei"),
            };
            Frog[] frogs = new Frog[]
            {
                new Frog("Furi", 2, true),
                new Frog("Mani", 3, false),
                new Frog("Perr", 2, false),
            };
            Kitten[] kittens = new Kitten[]
            {
                new Kitten("Stupi", 1, "Persian"),
                new Kitten("Lili", 1, "Persian"),
                new Kitten("Plupi", 2, "Angora"),
            };
            Tomcat[] tomcats = new Tomcat[]
            {
                new Tomcat("Gunko", 4),
                new Tomcat("Porfavor", 3),
                new Tomcat("Kalin", 5),
            };

            double dogsAvAge = Animal.AverageAge(dogs);
            double catsAvAge = Animal.AverageAge(cats);
            double frogsAvAge = Animal.AverageAge(frogs);
            double kittensAvAge = Animal.AverageAge(kittens);
            double tomcatsAvAge = Animal.AverageAge(tomcats);

            Console.WriteLine("Average age: \nDogs: {0:F1};\nCats: {1:F1};\nFrogs: {2:F1};\nKittens: {3:F1};\nTomcats: {4:F1};",
                dogsAvAge, catsAvAge, frogsAvAge, kittensAvAge, tomcatsAvAge);
            Console.WriteLine();

            Console.WriteLine("Different animals sounds:");
            Console.Write("Cats: ");
            cats[0].ProduceSound();
            Console.Write("Dogs: ");
            dogs[1].ProduceSound();
            Console.Write("Frogs: ");
            frogs[2].ProduceSound();
            Console.WriteLine();

            Console.WriteLine("Different animals character activities:");
            Console.WriteLine(dogs[2].SpinTail());
            Console.WriteLine(cats[1].Tease());
            Console.WriteLine(frogs[2].Jump());
        }
Exemplo n.º 2
0
        private static Animal CreatingAnimal(Animal animal, string animalType, string animalName, int animalAge, string animalGender)
        {
            switch (animalType)
            {
            case "Dog":
                animal = new Dog(animalName, animalAge, animalGender);
                break;

            case "Frog":
                animal = new Frog(animalName, animalAge, animalGender);
                break;

            case "Cat":
                animal = new Cat(animalName, animalAge, animalGender);
                break;

            case "Kitten":
                animal = new Kitten(animalName, animalAge);
                break;

            case "Tomcat":
                animal = new Tomcat(animalName, animalAge);
                break;
            }

            return(animal);
        }
Exemplo n.º 3
0
        private static string CreateNewSpecificAnimal(string type)
        {
            switch (type)
            {
            case "Cat":
                Cat cat = new Cat(animalName, animalAge, animalGender);
                return(cat.ToString());

            case "Dog":
                Dog dog = new Dog(animalName, animalAge, animalGender);
                return(dog.ToString());

            case "Frog":
                Frog frog = new Frog(animalName, animalAge, animalGender);
                return(frog.ToString());

            case "Kitten":
                Kitten kitten = new Kitten(animalName, animalAge);
                return(kitten.ToString());

            case "Tomcat":
                Tomcat tomcat = new Tomcat(animalName, animalAge);
                return(tomcat.ToString());

            default:
                return(null);
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            var jaba     = new Frog("baba jaba", 1, Genders.Female);
            var kekerica = new Frog("kekerica", 3, Genders.Female);

            var sharo = new Dog("sharo", 3, Genders.Male);
            var sara  = new Dog("sara", 2, Genders.Female);
            var oldy  = new Dog("oldy", 12, Genders.Male);

            var puhi        = new Kitten("puhi", 2);
            var tommy       = new Tomcat("tommy", 4);
            var mouseKiller = new Cat("mousy", 5, Genders.Male);

            var animals = new List <Animal>()
            {
                jaba,
                kekerica,
                sharo,
                sara,
                puhi,
                tommy,
                mouseKiller,
                oldy
            };

            var avredgeAgeOfKinds = from a in animals
                                    group a by a.GetType().Name into g
                                    select new { GroupName = g.Key, AverageAge = g.ToList().Average(an => an.Age) };

            foreach (var animal in avredgeAgeOfKinds)
            {
                Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName, animal.AverageAge);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Cat    muca  = new Kitten("Muca", 2.5m);
            Kitten cuca  = new Kitten("Cuca", 10);
            Tomcat milko = new Tomcat("Milko", 7.2m);
            Cat    tom   = new Tomcat("Tom", 2);
            // Console.WriteLine(muca);
            Dog balkan = new Dog("Balkan", 1, Gender.male);
            Dog doncho = new Dog("Doncho", 5.5m, Gender.male);
            Dog goran  = new Dog("Goran", 6.5m, Gender.male);
            Dog milena = new Dog("Milena", 10, Gender.female);
            Dog conka  = new Dog("Conka", 15, Gender.female);

            //  Console.WriteLine(balkan);
            // balkan.ProduceSound();
            //  muca.ProduceSound();

            Frog lena   = new Frog("Lena", 1.7m, Gender.female);
            Frog mima   = new Frog("Mima", 2, Gender.female);
            Frog bogdan = new Frog("Bogdan", 0.7m, Gender.male);



            Cat[] cats = new Cat[4] {
                muca, cuca, milko, tom
            };
            Dog[] dogs = new Dog[5] {
                balkan, doncho, goran, milena, conka
            };
            Frog[] frogs = new Frog[3] {
                lena, mima, bogdan
            };
        }
Exemplo n.º 6
0
        public static void Main()
        {
            List <Animal> animals = new List <Animal>();

            string command = string.Empty;

            while (command != "Beast!")
            {
                command = Console.ReadLine();

                if (command == "Beast!")
                {
                    break;
                }

                List <string> tokens = Console.ReadLine().Split().ToList();

                Animal animal = null;

                try
                {
                    if (command == "Dog")
                    {
                        animal = new Dog(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    }
                    else if (command == "Frog")
                    {
                        animal = new Frog(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    }
                    else if (command == "Cat")
                    {
                        animal = new Cat(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    }
                    else if (command == "Tomcat" || command == "Kitten")
                    {
                        Cat cat;

                        if (tokens[2] == "Male")
                        {
                            animal = new Tomcat(tokens[0], int.Parse(tokens[1]), tokens[2]);
                        }
                        else
                        {
                            animal = new Kitten(tokens[0], int.Parse(tokens[1]), tokens[2]);
                        }
                    }

                    animals.Add(animal);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
Exemplo n.º 7
0
        public static Animal CreateAnimal(string animal, string name, int age, string gender)
        {
            Animal currentAnimal = null;

            switch (animal)
            {
            case "Dog":
                currentAnimal = new Dog(name, age, gender);
                break;

            case "Frog":
                currentAnimal = new Frog(name, age, gender);
                break;

            case "Cat":
                currentAnimal = new Cat(name, age, gender);
                break;

            case "Tomcat":
                currentAnimal = new Tomcat(name, age);
                break;

            case "Kitten":
                currentAnimal = new Kitten(name, age);
                break;
            }

            return(currentAnimal);
        }
Exemplo n.º 8
0
        public static void Main()
        {
            var animals = new List<Animal>();

            var kitten = new Kitten("Kitty", 2);

            SayAngAddToList(kitten, animals);

            var tomcat = new Tomcat("Tom", 1);

            SayAngAddToList(tomcat, animals);

            var frog = new Frog("Froggy", 5, Sex.Male);

            SayAngAddToList(frog, animals);

            var dog = new Dog("Sharo", 4, Sex.Male);

            SayAngAddToList(dog, animals);

            var anotherDog = new Dog("Lassy", 7, Sex.Female);

            SayAngAddToList(anotherDog, animals);

            Console.WriteLine("The average age of all animal is {0}", animals.Average(x => x.Age));
        }
Exemplo n.º 9
0
        private Animal GetAnimal(string firstCommand, string[] secondCommand)
        {
            string name   = secondCommand[0];
            int    age    = int.Parse(secondCommand[1]);
            string gender = secondCommand[2];

            Animal animal = null;

            if (firstCommand == "Dog")
            {
                animal = new Dog(name, age, gender);
            }
            else if (firstCommand == "Cat")
            {
                animal = new Cat(name, age, gender);
            }
            else if (firstCommand == "Frog")
            {
                animal = new Frog(name, age, gender);
            }
            else if (firstCommand == "Kitten")
            {
                animal = new Kitten(name, age);
            }
            else if (firstCommand == "Tomcat")
            {
                animal = new Tomcat(name, age);
            }
            else
            {
                throw new ArgumentException("Invalid input!");
            }

            return(animal);
        }
Exemplo n.º 10
0
        static void Main()
        {
            Animal max = new Dog("Max", 3, Gender.Male);
            Animal duke = new Dog("Duke", 1, Gender.Male);
            Animal fluffy = new Dog("Fluffy", 6, Gender.Male);
            Animal wink = new Dog("Wink", 3, Gender.Male);
            Animal abby = new Frog("Abby", 1, Gender.Female);
            Animal boogy = new Frog("Boogy", 2, Gender.Male);
            Animal pookie = new Frog("Pookie", 6, Gender.Female);
            Animal hermit = new Frog("Hermit", 2, Gender.Male);
            Animal abbey = new Kitten("Abbey", 1, Gender.Female);
            Animal panda = new Kitten("Panda", 1, Gender.Female);
            Animal ravi = new Tomcat("Ravi", 3, Gender.Male);
            Animal lexus = new Tomcat("Lexus", 9, Gender.Male);
            Animal biggie = new Cat("Biggie", 7, Gender.Male);
            Animal fig = new Cat("Fig", 7, Gender.Male);

            Animal[] animals = new Animal[] { max, duke, fluffy, wink, abby, boogy, pookie, hermit, abbey, panda, ravi, lexus, biggie, fig };

            var groupedAnimals =
                from an in animals
                group an by new { GroupName = an.GetType().Name } into grp
                select new
                {
                    GroupName = grp.Key.GroupName,
                    AverageAge = grp.Average(an => an.Age)
                };

            foreach (var animal in groupedAnimals)
            {
                Console.WriteLine("Group: {0} | Average Age: {1:F2}", animal.GroupName, animal.AverageAge);
            }
        }
        public static Animal GetAnimal(string animalType, string[] animalArgs)
        {
            Animal animal = null;

            string name   = animalArgs[0];
            int    age    = int.Parse(animalArgs[1]);
            Gender gender = animalArgs[2].ToLower() == "male" ? Gender.Male : Gender.Female;

            switch (animalType.ToLower())
            {
            case "dog":
                animal = new Dog(name, age, gender);
                break;

            case "frog":
                animal = new Frog(name, age, gender);
                break;

            case "cat":
                animal = new Cat(name, age, gender);
                break;

            case "tomcat":
                animal = new Tomcat(name, age);
                break;

            case "kitten":
                animal = new Kitten(name, age);
                break;
            }

            return(animal);
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            Dog    d = new Dog("Azorel", 5, "Male");
            Frog   f = new Frog("Oaki", 1, "Male");
            Cat    c = new Cat("Fifi", 6, "Female");
            Kitten k = new Kitten("Biscuit", 2, "Female");
            Tomcat t = new Tomcat("Yari", 10, "Male");

            var listaAnimale = new List <Animal>();

            listaAnimale.Add(d);
            listaAnimale.Add(f);
            listaAnimale.Add(c);
            listaAnimale.Add(k);
            listaAnimale.Add(t);

            foreach (var a in listaAnimale)
            {
                Console.WriteLine($"{a.Name}, {a.Age}, {a.Gender}");
            }

            double averageAge = 0;
            double counter    = 0;

            foreach (var x in listaAnimale)
            {
                averageAge = averageAge + (double)x.Age / 5;
                counter++;
            }
            Console.WriteLine($"Average age of the animals is: {averageAge}");

            Console.ReadKey();
        }
        private static Animal ExtractAnimal(string input, Animal animal, string name, int age, string gender)
        {
            if (input == "Cat")
            {
                animal = new Cat(name, age, gender);
            }
            else if (input == "Dog")
            {
                animal = new Dog(name, age, gender);
            }
            else if (input == "Frog")
            {
                animal = new Frog(name, age, gender);
            }
            else if (input == "Kitten")
            {
                animal = new Kitten(name, age, gender);
            }
            else if (input == "Tomcat")
            {
                animal = new Tomcat(name, age, gender);
            }

            return(animal);
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            Frog[] frogs = new Frog[5];
            frogs[0] = new Frog("Kermit", 5, 'M');
            frogs[1] = new Frog("Piggy", 8, 'F');
            frogs[2] = new Frog("Cookie Monster", 3, 'F');
            frogs[3] = new Frog("Oscar the grouch", 15, 'M');
            frogs[4] = new Frog("Kermit's double", 5, 'M');

            Dog[] dogs = new Dog[5];
            dogs[0] = new Dog("Rex", 1, 'M');
            dogs[1] = new Dog("Sergeant Dirty", 6, 'F');
            dogs[2] = new Dog("Lucky", 7, 'F');
            dogs[3] = new Dog("Unlucky", 2, 'M');
            dogs[4] = new Dog("Tramp", 4, 'M');

            Cat[] cats = new Cat[5];
            cats[0] = new Cat("Tom", 6, 'M');
            cats[1] = new Kitten("Princess", 1);
            cats[2] = new Cat("Jerry", 2, 'F');
            cats[3] = new Tomcat("Behemoth", 1);
            cats[4] = new Cat("Pluto", 7, 'M');

            Console.WriteLine("The average age of the frogs is " + Animal.AverageAge(frogs));
            Console.WriteLine("The average age of the dogs is " + Animal.AverageAge(dogs));
            Console.WriteLine("The average age of the cats is " + Animal.AverageAge(cats));
        }
Exemplo n.º 15
0
        static void Main()
        {
            var scooby = new Dog("Scooby", 2, 'm');
            var frogy = new Frog("Frogy", 0.5, 'm');
            var tommy = new Cat("Tommy", 1, 'm');
            var kitty = new Kitten("Kitty", 0.8, 'f');
            var speedy = new Tomcat("Speedy", 1.5, 'f');
            var spark = new Dog("Spark", 3, 'm');
            var carmit = new Frog("Carmit", 1, 'm');
            var jenny = new Kitten("Jenny", 1.2, 'f');

            var animals = new Animal[] { scooby, spark, frogy, tommy, kitty, speedy };
            var differentAnimals = new Animal[] { tommy, kitty, carmit, jenny };

            foreach (var animal in animals)
            {
                Console.Write(animal);
                animal.ProduceSound();
                Console.WriteLine();
            }

            var groupedAnimals =
                from anim in animals
                group anim by (anim is Cat) ? typeof (Cat) : anim.GetType()
                into g
                select new {GroupName = g.Key, AverageAge = g.ToList().Average(an => an.Age)};

            foreach (var animal in groupedAnimals)
            {
                Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName.Name, animal.AverageAge);
            }
        }
        private Animal GetAnimal(string animalType, string[] animalDetails)
        {
            string name = animalDetails[0];
            int    age  = int.Parse(animalDetails[1]);

            string gender = GetGender(animalDetails);

            Animal animal = null;

            if (animalType == "Dog")
            {
                animal = new Dog(name, age, gender);
            }
            else if (animalType == "Frog")
            {
                animal = new Frog(name, age, gender);
            }
            else if (animalType == "Cat")
            {
                animal = new Cat(name, age, gender);
            }
            else if (animalType == "Tomcat")
            {
                animal = new Tomcat(name, age);
            }
            else if (animalType == "Kitten")
            {
                animal = new Kitten(name, age);
            }

            return(animal);
        }
Exemplo n.º 17
0
        private Animal GetAnimal(string type, string[] args)
        {
            Animal animal = null;
            var    name   = args[0];
            var    age    = int.Parse(args[1]);
            string gender = null;

            if (args.Length == 3)
            {
                gender = args[2];
            }

            if (type == "Dog")
            {
                animal = new Dog(name, age, gender);
            }
            else if (type == "Frog")
            {
                animal = new Frog(name, age, gender);
            }
            else if (type == "Cat")
            {
                animal = new Cat(name, age, gender);
            }
            else if (type == "Kitten")
            {
                animal = new Kitten(name, age);
            }
            else if (type == "Tomcat")
            {
                animal = new Tomcat(name, age);
            }

            return(animal);
        }
Exemplo n.º 18
0
        public static void Main(string[] args)
        {
            var jaba = new Frog("baba jaba", 1, Genders.Female);
            var kekerica = new Frog("kekerica", 3, Genders.Female);

            var sharo = new Dog("sharo", 3, Genders.Male);
            var sara = new Dog("sara", 2, Genders.Female);
            var oldy = new Dog("oldy", 12, Genders.Male);

            var puhi = new Kitten("puhi", 2);
            var tommy = new Tomcat("tommy", 4);
            var mouseKiller = new Cat("mousy", 5, Genders.Male);

            var animals = new List<Animal>()
            {
                jaba, 
                kekerica,
                sharo,
                sara,
                puhi,
                tommy,
                mouseKiller,
                oldy
            };
            
            var avredgeAgeOfKinds = from a in animals
                                    group a by a.GetType().Name into g
                                    select new { GroupName = g.Key, AverageAge = g.ToList().Average(an => an.Age) };
            foreach (var animal in avredgeAgeOfKinds)
            {
                Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName, animal.AverageAge);
            }
        }
Exemplo n.º 19
0
        static void Main()
        {
            Dog kuche = new Dog("Kudjo", "Male", 12);

            kuche.ProduceSound();

            Dog[] dogs = new Dog[]
            {
                new Dog("Dog1", "Male", 12),
                new Dog("Dog2", "Male", 5),
                new Dog("Dog3", "Male", 5),
                new Dog("Dog4", "Male", 6),
                new Dog("Dog5", "Male", 8),
            };
            int avgYearsDogs = Animal.AvgAge(dogs);

            Tomcat[] cats = new Tomcat[]
            {
                new Tomcat("cat1", "Male", 12),
                new Tomcat("cat2", "Male", 11),
                new Tomcat("cat3", "Male", 2),
                new Tomcat("cat4", "Male", 5),
                new Tomcat("cat5", "Male", 7),
                new Tomcat("cat6", "Male", 18),
            };
            int avg = Animal.AvgAge(cats);

            Console.WriteLine("Dog average age: {0}", avgYearsDogs);
        }
Exemplo n.º 20
0
 private static void AddAnimalToList(int animalAge)
 {
     if (animalType == "Cat")
     {
         Cat cat = new Cat(animalName, animalAge, animalGender);
         animals.Add(cat);
     }
     else if (animalType == "Dog")
     {
         Dog dog = new Dog(animalName, animalAge, animalGender);
         animals.Add(dog);
     }
     else if (animalType == "Frog")
     {
         Frog frog = new Frog(animalName, animalAge, animalGender);
         animals.Add(frog);
     }
     else if (animalType == "Kitten")
     {
         Kitten kitten = new Kitten(animalName, animalAge);
         animals.Add(kitten);
     }
     else if (animalType == "Tomcat")
     {
         Tomcat tomcat = new Tomcat(animalName, animalAge);
         animals.Add(tomcat);
     }
 }
Exemplo n.º 21
0
        public static void Main()
        {
            var animals = new List <Animal>();

            var kitten = new Kitten("Kitty", 2);

            SayAngAddToList(kitten, animals);

            var tomcat = new Tomcat("Tom", 1);

            SayAngAddToList(tomcat, animals);

            var frog = new Frog("Froggy", 5, Sex.Male);

            SayAngAddToList(frog, animals);

            var dog = new Dog("Sharo", 4, Sex.Male);

            SayAngAddToList(dog, animals);

            var anotherDog = new Dog("Lassy", 7, Sex.Female);

            SayAngAddToList(anotherDog, animals);

            Console.WriteLine("The average age of all animal is {0}", animals.Average(x => x.Age));
        }
        static void Main(string[] args)
        {
            string        type       = Console.ReadLine();
            List <Animal> allAnimals = new List <Animal>();

            while (type != "Beast!")
            {
                Animal   animal;
                string[] animalTokens = Console.ReadLine().Split();
                if (animalTokens.Length < 2)
                {
                    throw new ArgumentException("Invalid input!");
                }
                string name = animalTokens[0];
                int    age  = int.Parse(animalTokens[1]);
                if (age < 0)
                {
                    throw new ArgumentException("Invalid input!");
                }
                string gender = animalTokens[2];
                switch (type)
                {
                case "Cat":
                    animal = new Cat(name, age, gender);
                    allAnimals.Add(animal);
                    break;

                case "Dog":
                    animal = new Dog(name, age, gender);
                    allAnimals.Add(animal);
                    break;

                case "Frog":
                    animal = new Frog(name, age, gender);
                    allAnimals.Add(animal);
                    break;

                case "Kitten":
                    animal = new Kitten(name, age);
                    allAnimals.Add(animal);
                    break;

                case "Tomcat":
                    animal = new Tomcat(name, age);
                    allAnimals.Add(animal);
                    break;

                default:
                    throw new ArgumentException("Invalid input!");
                }

                type = Console.ReadLine();
            }
            foreach (var item in allAnimals)
            {
                Console.WriteLine(item.GetType().Name);
                Console.WriteLine($"{item.Name} {item.Age} {item.Gender}");
                Console.WriteLine(item.ProduceSound());
            }
        }
        private void AddAnimal(List <Animal> animals, string command, string name, int age, string gender)
        {
            switch (command)
            {
            case "Dog":
                Dog dog = new Dog(name, age, gender);
                animals.Add(dog);
                break;

            case "Frog":
                Frog frog = new Frog(name, age, gender);
                animals.Add(frog);
                break;

            case "Cat":
                Cat cat = new Cat(name, age, gender);
                animals.Add(cat);
                break;

            case "Kitten":
                Kitten kitten = new Kitten(name, age);
                animals.Add(kitten);
                break;

            case "Tomcat":
                Tomcat tomcat = new Tomcat(name, age);
                animals.Add(tomcat);
                break;
            }
        }
Exemplo n.º 24
0
        private Animal GetAnimal(string type, string[] animalArgs)
        {
            string name = animalArgs[0];
            int    age  = int.Parse(animalArgs[1]);

            Animal animal = null;

            if (type == "Dog")
            {
                animal = new Dog(name, age, animalArgs[2]);
            }
            else if (type == "Cat")
            {
                animal = new Cat(name, age, animalArgs[2]);
            }
            else if (type == "Frog")
            {
                animal = new Frog(name, age, animalArgs[2]);
            }
            else if (type == "Kitten")
            {
                animal = new Kitten(name, age);
            }
            else if (type == "Tom")
            {
                animal = new Tomcat(name, age);
            }
            else
            {
                throw new ArgumentException("Invalid inout!");
            }
            return(animal);
        }
Exemplo n.º 25
0
        public Animal CreateAnimal()
        {
            string name   = animalInfo[0];
            int    age    = int.Parse(animalInfo[1]);
            string gender = animalInfo[2];

            Animal newAnimal = new Animal(name, age, gender);

            switch (typeAnimal)
            {
            case "Cat":
                newAnimal = new Cat(name, age, gender);
                break;

            case "Frog":
                newAnimal = new Frog(name, age, gender);
                break;

            case "Dog":
                newAnimal = new Dog(name, age, gender);
                break;

            case "Kitten":
                newAnimal = new Kitten(name, age);
                break;

            case "Tomcat":
                newAnimal = new Tomcat(name, age);
                break;
            }

            return(newAnimal);
        }
Exemplo n.º 26
0
        public static void Main(string[] args)
        {
            string        animalType = Console.ReadLine();
            List <Animal> animals    = new List <Animal>();

            while (animalType != "Beast!")
            {
                string[] animalInfo = Console.ReadLine().Split();
                //Tom 12 Male

                string name   = animalInfo[0];
                int    age    = int.Parse(animalInfo[1]);
                string gender = animalInfo[2];

                try
                {
                    Animal animal = new Animal(name, age, gender);

                    if (animalType == "Tomcat")
                    {
                        animal = new Tomcat(name, age);
                    }

                    else if (animalType == "Kitten")
                    {
                        animal = new Kitten(name, age);
                    }

                    else if (animalType == "Cat")
                    {
                        animal = new Cat(name, age, gender);
                    }

                    else if (animalType == "Dog")
                    {
                        animal = new Dog(name, age, gender);
                    }

                    else if (animalType == "Frog")
                    {
                        animal = new Frog(name, age, gender);
                    }

                    animals.Add(animal);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animalType = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.GetType().Name);
                Console.WriteLine(animal.ToString());
                Console.WriteLine(animal.ProduceSound());
            }
        }
Exemplo n.º 27
0
        private Animal GetAnimal(string animalType, string[] animalArguments)
        {
            string name   = animalArguments[0];
            int    age    = int.Parse(animalArguments[1]);
            string gender = this.GetGender(animalType, animalArguments);

            Animal animal = null;

            if (animalType == "Dog")
            {
                animal = new Dog(name, age, gender);
            }
            else if (animalType == "Cat")
            {
                animal = new Cat(name, age, gender);
            }
            else if (animalType == "Frog")
            {
                animal = new Frog(name, age, gender);
            }
            else if (animalType == "Kitten")
            {
                animal = new Kitten(name, age);
            }
            else if (animalType == "Tomcat")
            {
                animal = new Tomcat(name, age);
            }
            else
            {
                throw new ArgumentException("Invalid input!");
            }

            return(animal);
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            Cat    kitty   = new Cat("Kitty", 5, Genders.Female);
            Tomcat charlie = new Tomcat("Charlie", 20, Genders.Male);
            Kitten ellie   = new Kitten("Ellie", 1, Genders.Female);

            Dog ares  = new Dog("Ares", 2, Genders.Male);
            Dog rocky = new Dog("Rocky", 5, Genders.Male);
            Dog daisy = new Dog("Daisy", 5, Genders.Female);

            Frog casper = new Frog("Casper", 3, Genders.Male);
            Frog abby   = new Frog("Abby", 2, Genders.Female);

            List <Animal> animals = new List <Animal>()
            {
                kitty,
                charlie,
                ellie,
                ares,
                rocky,
                daisy,
                casper,
                abby
            };

            var groupedAnimals = from animal in animals
                                 group animal by(animal is Cat) ? typeof(Cat) : animal.GetType() into g
                                 select new { GroupName = g.Key, AverageAge = g.ToList().Average(animal => animal.Age) };

            foreach (var animal in groupedAnimals)
            {
                Console.WriteLine("{0} - average age : {1:F2}", animal.GroupName.Name, animal.AverageAge);
            }
        }
Exemplo n.º 29
0
        static void Main()
        {
            // Attention! - No animals were harmed during these tests

            Console.Title = "Animals";

            var dog = new Dog("Gosho", 3, Gender.Male);

            Console.WriteLine(dog);
            dog.FetchStick();
            Console.Write(Environment.NewLine);

            var frog = new Frog("Masha", 16, Gender.Female);

            Console.WriteLine(frog);
            frog.Transform();
            Console.Write(Environment.NewLine);

            var kitty = new Kitten("Maca", 0);

            Console.WriteLine(kitty);
            kitty.MeltYourHeart();
            Console.Write(Environment.NewLine);

            var tomcat = new Tomcat("Tom", 4);

            Console.WriteLine(tomcat);
            tomcat.Piss();
            Console.Write(Environment.NewLine);

            var animals = new Animal[]
            {
                new Dog("Freya", 1, Gender.Female),
                new Dog("Sharo", 4, Gender.Male),
                new Frog("Penka", 20, Gender.Female),
                new Frog("Fred", 32, Gender.Male),
                new Kitten("Merlin", 1),
                new Kitten("Shusia", 0),
                new Tomcat("Felix", 6),
                new Tomcat("Silvester", 5),
            };

            var averageAge = from an in animals
                             group an by new
            {
                GroupName = an.GetType().Name
            }
            into gender select new
            {
                gender.Key.GroupName,
                AvarageAge = gender.Average(an => an.Age)
            };

            foreach (var animal in averageAge)
            {
                Console.WriteLine(String.Format("Group: {0}, AvarageAge: {1:0.00}.", animal.GroupName, animal.AvarageAge));
            }

            // And what does the Fox say? Oh, no foxes here...
        }
        public static void Main()
        {
            List <Animal> animals = new List <Animal>();

            while (true)
            {
                string firstLine = Console.ReadLine();

                if (firstLine == "Beast!")
                {
                    break;
                }

                string[] secondLineTokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                // Spravka tuk: https://softuni.bg/forum/15928/problem-s-06-animals-ot-oop-basics-inheritance
                try
                {
                    switch (firstLine)
                    {
                    case "Dog":
                        var dog = new Dog(secondLineTokens[0], int.Parse(secondLineTokens[1]), secondLineTokens[2]);
                        animals.Add(dog);
                        break;

                    case "Frog":
                        var frog = new Frog(secondLineTokens[0], int.Parse(secondLineTokens[1]), secondLineTokens[2]);
                        animals.Add(frog);
                        break;

                    case "Cat":
                        var cat = new Cat(secondLineTokens[0], int.Parse(secondLineTokens[1]), secondLineTokens[2]);
                        animals.Add(cat);
                        break;

                    case "Kitten":
                        var kitten = new Kitten(secondLineTokens[0], int.Parse(secondLineTokens[1]));
                        animals.Add(kitten);
                        break;

                    case "Tomcat":
                        var tomcat = new Tomcat(secondLineTokens[0], int.Parse(secondLineTokens[1]));
                        animals.Add(tomcat);
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 31
0
        static void Main(string[] args)
        {
            //Animal f = new Cat("F", 10, "M");
            //Console.WriteLine(f);
            //f.produceSound();

            string input = Console.ReadLine();

            while (input != "Beast!")
            {
                try
                {
                    string   animalType = input;
                    string[] animalArgs = Console.ReadLine().Split(' ');
                    string   name       = animalArgs[0];
                    int      age        = int.Parse(animalArgs[1]);
                    string   gender     = animalArgs[2];
                    string   nameSpace  = "Animals";

                    switch (animalType)
                    {
                    case "Cat":
                        Animal cat = new Cat(name, age, gender);
                        Console.WriteLine(cat);
                        cat.produceSound();
                        break;

                    case "Dog":
                        Animal dog = new Dog(name, age, gender);
                        Console.WriteLine(dog);
                        dog.produceSound();
                        break;

                    case "Frog":
                        Animal frog = new Frog(name, age, gender);
                        Console.WriteLine(frog);
                        frog.produceSound();
                        break;

                    case "Kitten":
                        Animal kitten = new Kitten(name, age, gender);
                        Console.WriteLine(kitten);
                        kitten.produceSound();
                        break;

                    case "Tomcat":
                        Animal tomcat = new Tomcat(name, age, gender);
                        Console.WriteLine(tomcat);
                        tomcat.produceSound();
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                input = Console.ReadLine();
            }
        }
Exemplo n.º 32
0
        static void Main()
        {
            // create some animals from each class and print them
            Dog dog = new Dog("Sharo", 3, Gender.Male);
            Console.WriteLine(dog);
            dog.FetchStick();

            Console.WriteLine();

            Frog frog = new Frog("Kermit", 33, Gender.Male);
            Console.WriteLine(frog);
            frog.Jump();

            Console.WriteLine();

            Kitten kitty = new Kitten("Kitty", 1);
            Console.WriteLine(kitty);
            kitty.Cry();

            Console.WriteLine();

            Tomcat tomcat = new Tomcat("Tom", 12);
            Console.WriteLine(tomcat);
            tomcat.Piss();

            Console.WriteLine();

            // create an array of Animals
            Animal[] animals = new Animal[]
            {
                new Dog("Rex",3, Gender.Male),
                new Frog("Kekerica", 1, Gender.Female),
                new Kitten("Pisi", 1),
                new Tomcat("Tom",2),
                new Dog("Erik", 4, Gender.Male),
                new Frog("Penka", 1, Gender.Female),
                new Kitten("Jasmin", 2),
                new Tomcat("Kolio",6),
                new Dog("Bender",2, Gender.Male),
                new Frog("Ginka", 6, Gender.Female),
                new Kitten("Tedy", 1),
                new Tomcat("Muncho",4),
            };

            // calculate the aveage age of each animal and print them 
            var averageAge =
                from an in animals
                group an by new { GroupName = an.GetType().Name } into gr
                select new
                {
                    GroupName = gr.Key.GroupName,
                    AvarageAge = gr.Average(an => an.Age)
                };

            foreach (var animal in averageAge)
            {
                Console.WriteLine(String.Format("Group: {0}, AvarageAge: {1:0.00}.", animal.GroupName, animal.AvarageAge));
            }
        }
Exemplo n.º 33
0
        public void Run()
        {
            string animalType = Console.ReadLine();

            while ((animalType = Console.ReadLine()) != "Beast!")
            {
                string[] animalInfo = Console.ReadLine()
                                      .Split(" ");

                Animal animal;

                try
                {
                    string name   = animalInfo[0];
                    int    age    = int.Parse(animalInfo[1]);
                    string gender = null;
                    gender = GetGender(animalInfo, gender);

                    animal = null;

                    if (animalType == "Cat")
                    {
                        animal = new Cat(name, age, gender);
                    }
                    else if (animalType == "Dog")
                    {
                        animal = new Dog(name, age, gender);
                    }
                    else if (animalType == "Frog")
                    {
                        animal = new Frog(name, age, gender);
                    }
                    else if (animalType == "Kitten")
                    {
                        animal = new Kitten(name, age);
                    }
                    else if (animalType == "Tomcat")
                    {
                        animal = new Tomcat(name, age);
                    }
                    else
                    {
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }

                this.animals.Add(animal);
            }

            foreach (Animal animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 34
0
        static void Main(string[] args)
        {
            try
            {
                Cat rijko = new Cat("rijko", 5, "male");
                Console.WriteLine(rijko.ToString());
                rijko.ProduceSound();

                Tomcat darko = new Tomcat("darko", 3);
                Console.WriteLine(darko.ToString());
                darko.ProduceSound();

                Frog kikerana = new Frog("kikerana", 1, "female");
                Console.WriteLine(kikerana.ToString());
                kikerana.ProduceSound();

                Dog sharo = new Dog("sharo", 9);
                Console.WriteLine(sharo.ToString());
                sharo.ProduceSound();

                Animal[] animals = new Animal[] {
                    rijko,
                    darko,
                    kikerana,
                    sharo,
                    new Cat("tom", 2),
                    new Dog("zoro", 9),
                    new Cat("kotka", 4, "male")
                };

                Console.WriteLine();

                foreach (var animal in animals)
                {
                    Console.WriteLine(animal.ToString());
                }

                Console.WriteLine();


                var groupAnimals =
                    from animal in animals
                    group animal by animal.GetType().Name into typeGroup
                    select new
                {
                    typeGroup.Key,
                    AverageValue = Math.Round(typeGroup.Average(i => i.Age), 2)
                };

                foreach (var typeGroup in groupAnimals)
                {
                    Console.WriteLine("{0}s: average age is:{1}", typeGroup.Key, typeGroup.AverageValue);
                }
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 35
0
        public void Run()
        {
            string animalType = Console.ReadLine();

            while (animalType != "Beast!")
            {
                try
                {
                    string[] animalArgs = Console.ReadLine().Split();

                    string name   = animalArgs[0];
                    int    age    = int.Parse(animalArgs[1]);
                    string gender = animalArgs[2];

                    switch (animalType)
                    {
                    case "Cat":
                        Cat cat = new Cat(name, age, gender);
                        animals.Add(cat);
                        break;

                    case "Dog":
                        Dog dog = new Dog(name, age, gender);
                        animals.Add(dog);
                        break;

                    case "Frog":
                        Frog frog = new Frog(name, age, gender);
                        animals.Add(frog);
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(name, age);
                        animals.Add(kitten);
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(name, age);
                        animals.Add(tomcat);
                        break;

                    default:
                        Console.WriteLine("Invalid input!");
                        break;
                    }
                }
                catch (InvalidInputException exception)
                {
                    Console.WriteLine(exception.Message);
                }

                animalType = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
Exemplo n.º 36
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    string animalType = Console.ReadLine();
                    if (animalType == "Beast!")
                    {
                        break;
                    }
                    string[] animalArgs = Console.ReadLine().Split();
                    switch (animalType)
                    {
                    case "Dog":
                        Dog dog = new Dog(animalArgs);
                        dog.GetTypeOfAnimal();
                        Console.WriteLine(dog.ToString());
                        dog.ProduceSound();
                        break;

                    case "Cat":
                        Cat cat = new Cat(animalArgs);
                        cat.GetTypeOfAnimal();
                        Console.WriteLine(cat.ToString());
                        cat.ProduceSound();
                        break;

                    case "Frog":
                        Frog frog = new Frog(animalArgs);
                        frog.GetTypeOfAnimal();
                        Console.WriteLine(frog.ToString());
                        frog.ProduceSound();
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(animalArgs);
                        kitten.GetTypeOfAnimal();
                        Console.WriteLine(kitten.ToString());
                        kitten.ProduceSound();
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(animalArgs);
                        tomcat.GetTypeOfAnimal();
                        Console.WriteLine(tomcat.ToString());
                        tomcat.ProduceSound();
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        static void Main(string[] args)
        {
            while (true)
            {
                string comand = Console.ReadLine();

                if (comand == "Beast!")
                {
                    break;
                }

                string[] input  = Console.ReadLine().Split();
                string   name   = input[0];
                int      age    = int.Parse(input[1]);
                string   gender = input[2];

                if (string.IsNullOrEmpty(name) || age < 0 || string.IsNullOrEmpty(gender))
                {
                    Console.WriteLine("Invalid input!");
                    continue;
                }

                if (comand == "Cat")
                {
                    Cat cat = new Cat(name, age, gender);
                    Console.WriteLine(cat);
                    Console.WriteLine(cat.ProduceSound());
                }

                if (comand == "Dog")
                {
                    Dog dog = new Dog(name, age, gender);
                    Console.WriteLine(dog);
                    Console.WriteLine(dog.ProduceSound());
                }

                if (comand == "Frog")
                {
                    Frog frog = new Frog(name, age, gender);
                    Console.WriteLine(frog);
                    Console.WriteLine(frog.ProduceSound());
                }

                if (comand == "Kitten")
                {
                    Kitten kitten = new Kitten(name, age);
                    Console.WriteLine(kitten);
                    Console.WriteLine(kitten.ProduceSound());
                }

                if (comand == "Tomcat")
                {
                    Tomcat tomcat = new Tomcat(name, age);
                    Console.WriteLine(tomcat);
                    Console.WriteLine(tomcat.ProduceSound());
                }
            }
        }
        static void Main()
        {
            // Attention! - No animals were harmed during these tests

            Console.Title = "Animals";

            var dog = new Dog("Gosho", 3, Gender.Male);
            Console.WriteLine(dog);
            dog.FetchStick();
            Console.Write(Environment.NewLine);

            var frog = new Frog("Masha", 16, Gender.Female);
            Console.WriteLine(frog);
            frog.Transform();
            Console.Write(Environment.NewLine);

            var kitty = new Kitten("Maca", 0);
            Console.WriteLine(kitty);
            kitty.MeltYourHeart();
            Console.Write(Environment.NewLine);

            var tomcat = new Tomcat("Tom", 4);
            Console.WriteLine(tomcat);
            tomcat.Piss();
            Console.Write(Environment.NewLine);

            var animals = new Animal[]
            {
                new Dog("Freya", 1, Gender.Female),
                new Dog("Sharo", 4, Gender.Male),
                new Frog("Penka", 20, Gender.Female),
                new Frog("Fred", 32, Gender.Male),
                new Kitten("Merlin", 1),
                new Kitten("Shusia", 0),
                new Tomcat("Felix",6),
                new Tomcat("Silvester", 5),
            };

            var averageAge = from an in animals
                group an by new
                {
                    GroupName = an.GetType().Name
                }
                into gender select new
                {
                    gender.Key.GroupName,
                    AvarageAge = gender.Average(an => an.Age)
                };

            foreach (var animal in averageAge)
            {
                Console.WriteLine(String.Format("Group: {0}, AvarageAge: {1:0.00}.", animal.GroupName, animal.AvarageAge));
            }

            // And what does the Fox say? Oh, no foxes here...
        }
Exemplo n.º 39
0
        static void Main()
        {
            Dog dog = new Dog("Sharo", 5, Gender.Male);
            Console.WriteLine(dog);

            Console.WriteLine();

            Frog frog = new Frog("Kermit", 33, Gender.Male);
            Console.WriteLine(frog);

            Console.WriteLine();

            Kitten kitty = new Kitten("Kitty", 1);
            Console.WriteLine(kitty);

            Console.WriteLine();

            Tomcat tomcat = new Tomcat("Tom", 12);
            Console.WriteLine(tomcat);

            Console.WriteLine();


            List<Animal> animals = new List<Animal>()
            {
                new Dog("Rex",3, Gender.Male),
                new Frog("Kekerica", 1, Gender.Female),
                new Kitten("Pisi", 1),
                new Tomcat("Tom",2),
                new Dog("Erik", 4, Gender.Male),
                new Frog("Penka", 1, Gender.Female),
                new Kitten("Jasmin", 2),
                new Tomcat("Kolio",6),
                new Dog("Bender",2, Gender.Male),
                new Frog("Ginka", 6, Gender.Female),
                new Kitten("Tedy", 1),
                new Tomcat("Muncho",4),
            };

            var avgGradeForCurrentAnimal = animals
                .GroupBy(x => x.GetType().Name)
                .Select(a => new
                {
                    Name = a.Key,
                    AvgAge = a.Average(g => g.Age)
                });

            foreach (var currAnimal in avgGradeForCurrentAnimal)
            {
                Console.WriteLine(currAnimal);
            }
        }
Exemplo n.º 40
0
        static void Main(string[] args)
        {
            Cat cat = new Cat("Pesho",12, Gender.Male);
            Tomcat[] tomcats = new Tomcat[]
            {
                new Tomcat("Pesho",13),
                new Tomcat("Goshko",12),
                new Tomcat("Pencho",6),
                new Tomcat("Gencho",2)
            };

            Console.WriteLine("The average age of our tomcats is:{0}",Tomcat.AverageAge(tomcats));
        }
Exemplo n.º 41
0
        static void Main(string[] args)
        {
            Dog pinchi = new Dog("Pinchi", 2, "male", "bauuuuuuuu");
            Dog suzi = new Dog("Pinchi", 4, "male", "bauuuuuuuu");
            Dog djeimi = new Dog("Pinchi", 4, "male", "bauuuuuuuu");

            Kitten mimi = new Kitten("kitten", 5, "female", "miiiauuu");
            Kitten kuki = new Kitten("kitten", 5, "female", "miiiauuu");

            Tomcat tom = new Tomcat("Top4o", 15, "male", "myuuuu");

            Frog crazy = new Frog("Crazy Frog", 10, "male", "Kvaaa");
            Console.WriteLine(Frog.AverageFrog().Count());
        }
Exemplo n.º 42
0
        static void Main(string[] args)
        {
            Animal pesho = new Dog("Pesho", 19, "male");
            Cat tom = new Tomcat("Tommy", 12);
            Dog koche = new Dog("Koche", 10, "male");

            List<Animal> animals = new List<Animal>();

            animals.Add(pesho);
            animals.Add(tom);
            animals.Add(koche);

            animals.OrderBy(x=>x.Name).ToList().ForEach(Console.WriteLine);

            koche.ProduceSound();
            (pesho as Dog).ProduceSound();
            tom.ProduceSound();
        }
Exemplo n.º 43
0
        static void Main()
        {
            Random rand = new Random();
            Dog[] dogs = new Dog[5];
            Frog[] frogs = new Frog[5];
            Cat[] cats = new Cat[5];
            Kitten[] kittens = new Kitten[5];
            Tomcat[] tomcats = new Tomcat[5];
            for (int i = 0; i < 5; i++)
            {
                int age=rand.Next(0,30);
                Dog dog = new Dog(age, Convert.ToString((char)(age + 65)), "male");
                dogs[i] = dog;

                age = rand.Next(0, 30);
                Frog frog = new Frog(age, Convert.ToString((char)(age + 65)), "male");
                frogs[i] = frog;

                age = rand.Next(0, 30);
                Kitten kiten = new Kitten(age, Convert.ToString((char)(age + 65)), "male");
                kittens[i] = kiten;

                age = rand.Next(0, 30);
                Cat cat = new Cat(age, Convert.ToString((char)(age + 65)), "male");
                cats[i] = cat;

                age = rand.Next(0, 30);
                Tomcat tomcat = new Tomcat(age, Convert.ToString((char)(age + 65)), "male");
                tomcats[i] = tomcat;
            }
            Print(dogs);
            Print(cats);
            Print(kittens);
            Print(frogs);
            Print(tomcats);
            Console.WriteLine("The average age of the dogs is {0}", AverageAge(dogs));
            Console.WriteLine("The average age of the cats is {0}", AverageAge(cats));
            Console.WriteLine("The average age of the kittens is {0}", AverageAge(kittens));
            Console.WriteLine("The average age of the frogs is {0}", AverageAge(frogs));
            Console.WriteLine("The average age of the tomcats is {0}", AverageAge(tomcats));
        }
Exemplo n.º 44
0
        static void Main()
        {
            Cat someCat = new Cat("Kotka", 10);
            Cat someCat1 = new Cat("Kotka1", 5);

            Tomcat tom = new Tomcat("Tom", 4, Gender.Male);
            Tomcat tom1 = new Tomcat("Tom1", 3, Gender.Male);

            Kitten maca = new Kitten("Maca",2,Gender.Female);
            Kitten maca1 = new Kitten("Maca1", 6, Gender.Female);

            Dog sharo = new Dog("Sharo", 3);
            Dog sharo1 = new Dog("Sharo1", 1);

            Frog frogy = new Frog("Frogy", 8);
            Frog frogy1 = new Frog("Frogy1", 2);

            Console.WriteLine(someCat);
            Console.WriteLine(tom);
            Console.WriteLine( maca);
            Console.WriteLine(sharo);
            Console.WriteLine(frogy);

            IList<Animal> allAnimal = new List<Animal>();
            allAnimal.Add(someCat);
            allAnimal.Add(someCat1);
            allAnimal.Add(tom);
            allAnimal.Add(tom1);
            allAnimal.Add(maca);
            allAnimal.Add(maca1);
            allAnimal.Add(sharo);
            allAnimal.Add(sharo1);
            allAnimal.Add(frogy);
            allAnimal.Add(frogy1);

            foreach (var kind in allAnimal.GroupBy(x => x.GetType().Name))
            {
                double averageAge = kind.Select(x => x.Age).Average();
                Console.WriteLine("Animal : {0}, AverageAge: {1}", kind.Key, averageAge);
            }
        }
Exemplo n.º 45
0
        static void Main()
        {
            Tomcat tom = new Tomcat("Tom", 12);
            Console.WriteLine(tom);
            Kitten kitty = new Kitten("Kitty", 3);
            Console.WriteLine(kitty);
            Console.WriteLine();

            List<ISound> listAnimals = new List<ISound>();
            listAnimals.Add(new Cat("Pepi", 3, "female"));
            listAnimals.Add(new Frog("Kurmit", 10, "male"));
            listAnimals.Add(new Dog("Sharo", 5, "male"));
            listAnimals.Add(new Cat("Jorko", 6, "male"));
            listAnimals.Add(new Dog("Balkan", 10, "male"));
            listAnimals.Add(kitty);
            listAnimals.Add(tom);
            foreach (var animal in listAnimals)
            {
                Console.WriteLine(animal + " " + animal.MakeSound());
            }

            Console.WriteLine();

            Animal[] animals = new Animal[]
            {
                new Cat("Pepi", 3, "female"),
                new Frog("Kurmit", 10, "male"),
                new Dog("Sharo", 5, "male"),
                new Cat("Jorko", 6, "male"),
                new Cat("Tom",12,"male")
            };

               Console.WriteLine(Animal.GetAvaregeAge(animals));

               var ages =
               (from animal in animals
                where animal.GetType() == typeof(Cat)
                select animal.age).Average();
               Console.WriteLine(ages);
        }
Exemplo n.º 46
0
        private static void Main()
        {
            Dog barry = new Dog("Barry", 13, Gender.Male);
            Dog jessica = new Dog("Jessica", 6, Gender.Female);
            Dog milo = new Dog("Milo", 17, Gender.Male);

            Kitten dona = new Kitten("Dona", 6);
            Kitten sweety = new Kitten("Sweety", 0);
            Kitten sisi = new Kitten("Sisi", 4);

            Tomcat zorro = new Tomcat("Zorro", 7);
            Tomcat lucky = new Tomcat("Lucky", 7);
            Tomcat tom = new Tomcat("Tom", 7);

            Frog randy = new Frog("Randy", 3, Gender.Male);
            Frog bob = new Frog("Bob", 6, Gender.Male);
            Frog sw = new Frog("Sw", 2, Gender.Male);

            IList<Animal> allAnimal = new List<Animal>();
            allAnimal.Add(barry);
            allAnimal.Add(jessica);
            allAnimal.Add(milo);
            allAnimal.Add(dona);
            allAnimal.Add(sweety);
            allAnimal.Add(sisi);
            allAnimal.Add(zorro);
            allAnimal.Add(lucky);
            allAnimal.Add(tom);
            allAnimal.Add(randy);
            allAnimal.Add(bob);
            allAnimal.Add(sw);

            foreach (var kind in allAnimal.GroupBy(x => x.GetType().Name))
            {
                double averageAge = kind.Select(x => x.Age).Average();
                Console.WriteLine("Animal : {0}, average age are: {1:F2}", kind.Key, averageAge);
            }
        }
Exemplo n.º 47
0
        public static void Main()
        {
            Animal jaba = new Frog("baba jaba", 1, Genders.Female);
            Animal kekerica = new Frog("kekerica", 3, Genders.Female);

            Animal sharo = new Dog("sharo", 3, Genders.Male);
            Animal sara = new Dog("sara", 2, Genders.Female);
            Animal oldy = new Dog("oldy", 12, Genders.Male);

            Animal puhi = new Kitten("puhi", 2);
            Animal tommy = new Tomcat("tommy", 4);
            Animal mouseKiller = new Cat("mousy", 5, Genders.Male);

            List<Animal> animals = new List<Animal>()
            {
                jaba,
                kekerica,
                sharo,
                sara,
                puhi,
                tommy,
                mouseKiller,
                oldy
            };
            var groupedAnimals = from animal in animals
                                 group animal by (animal is Cat) ? typeof(Cat) : animal.GetType() into g
                                 select new { GroupName = g.Key, AverageAge = g.ToList().Average(an => an.Age) };

            foreach (var animal in groupedAnimals)
            {
                Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName.Name, animal.AverageAge);
            }

            puhi.ProduceSound();
            oldy.ProduceSound();
            jaba.ProduceSound();
        }
Exemplo n.º 48
0
        static void Main()
        {
            Kitten kitty = new Kitten("Pufi", 1); 
            Tomcat tomas = new Tomcat("Marko", 2);
            Dog sharo = new Dog("Kir4o", 3, SexEnum.male); 
            Frog squeek = new Frog("Kimi", 1, SexEnum.female); 
            kitty.MakeSomeNoise(); 
            tomas.MakeSomeNoise(); 
            sharo.MakeSomeNoise(); 
            squeek.MakeSomeNoise();
            
            Console.WriteLine(tomas.Gender); 
            Console.WriteLine(kitty.Gender); 

            Animal[] animals = 
            { 
                new Kitten("Koti", 2), 
                new Tomcat("Rocky", 4), 
                new Dog("Alex", 5, SexEnum.female), 
                new Frog("Siti", 2, SexEnum.female), 
                new Kitten("Kara", 6), 
                new Tomcat("Suzana", 2), 
                new Dog("Porsche", 7, SexEnum.female),
                new Frog("Kara", 10, SexEnum.female),
                new Kitten("Tonchi", 8), 
                new Tomcat("Jony", 8), 
                new Dog("Elma", 9, SexEnum.female), 
                new Frog("Liki", 5, SexEnum.female), 
            };

            var ordered = animals.GroupBy(x => x.GetType()); 
            Console.WriteLine(); 
            foreach (var animal in ordered) 
            { 
                Console.WriteLine("Average age of {0} is {1:F2}.", animal.Key.Name, animal.Average(x => x.Age));
            }
        }
Exemplo n.º 49
0
        static void Main(string[] args)
        {
            // Constructors test

            Kitten kity = new Kitten(10);

            Console.WriteLine("Kity's sex is : " + kity.Sex);

            Tomcat tommy = new Tomcat(10);

            Console.WriteLine("Tommy's sex is : " + tommy.Sex);

            Dog rex = new Dog(10,Sex.Male);

            Console.WriteLine("Rex's sex is : " + rex.Sex);
            Console.WriteLine("And Rex is {0} years old", rex.Age);

            Frog gogo = new Frog(100, Sex.Male);
            Console.WriteLine("Gogo the frog is {0} years old: ", gogo.Age);

            // Sounds test
            Console.WriteLine("__________________");
            Console.WriteLine("Frogs sound: ");
            gogo.ProduceSound();
            Console.WriteLine("__________________");
            Console.WriteLine("Tomcats sound: ");
            tommy.ProduceSound();
            Console.WriteLine("__________________");
            Console.WriteLine("Kittens sound: ");
            kity.ProduceSound();
            Console.WriteLine("__________________");
            Console.WriteLine("Dogs sound: ");
            rex.ProduceSound();

            Console.WriteLine();

            Dog[] dogs = new Dog[4]
            {
              new Dog(10,Sex.Male),
              new Dog(12,Sex.Male),
              new Dog(14,Sex.Male),
              new Dog(8,Sex.Male),
            };

            Frog[] frogs = new Frog[4]
            {
                new Frog(4,Sex.Male),
                new Frog(5,Sex.Male),
                new Frog(3,Sex.Male),
                new Frog(10,Sex.Male)

            };

            Kitten[] kities = new Kitten[4]
            {
                new Kitten(10),
                new Kitten(11),
                new Kitten(15),
                new Kitten(18)
            };

            Tomcat[] tomcats = new Tomcat[4]
            {
                new Tomcat(12),
                new Tomcat(15),
                new Tomcat(13),
                new Tomcat(40),
            };

            // Avarage age
            Console.WriteLine(" The avarage age of Tomcat is " + AvarageAge(tomcats));
            Console.WriteLine(" The avarage age of Kitten is " + AvarageAge(kities));
            Console.WriteLine(" The avarage age of Dogs is " + AvarageAge(dogs));
            Console.WriteLine(" The avarage age of Frogs is " + AvarageAge(frogs));

            Console.WriteLine();
        }
Exemplo n.º 50
0
        static void Main(string[] args)
        {
            Dog dog = new Dog("Pesho", 3, Gender.Male);
            Console.WriteLine(dog);
            dog.FetchStick();

            Console.WriteLine();

            Frog frog = new Frog("Peter", 33, Gender.Male);
            Console.WriteLine(frog);
            frog.Jump();

            Console.WriteLine();

            Kitten kitty = new Kitten("Ioio", 1);
            Console.WriteLine(kitty);
            kitty.Cry();

            Console.WriteLine();

            Tomcat tomcat = new Tomcat("Gogo", 12);
            Console.WriteLine(tomcat);
            tomcat.Piss();

            Console.WriteLine();

            // create an array of Animals
            Animal[] animals = new Animal[]
            {
                new Dog("Ares",3, Gender.Male),
                new Frog("Mitko", 1, Gender.Female),
                new Kitten("Mac", 1),
                new Tomcat("Cotka",2),
                new Dog("Saires", 4, Gender.Male),
                new Frog("Stilian", 1, Gender.Female),
                new Kitten("Ioio", 2),
                new Tomcat("Antony",6),
                new Dog("Roy",2, Gender.Male),
                new Frog("Angelina", 6, Gender.Female),
                new Kitten("Alex", 1),
                new Tomcat("Mecjo",4),
            };

            // calculate the aveage age of each animal and print them 
            var averageAge =
                from an in animals
                group an by new { GroupName = an.GetType().Name } into gr
                select new
                {
                    GroupName = gr.Key.GroupName,
                    AvarageAge = gr.Average(an => an.Age)
                };

            foreach (var animal in averageAge)
            {
                Console.WriteLine(String.Format("Group: {0}, AvarageAge: {1:0.00}.", animal.GroupName, animal.AvarageAge));
            }
        }
Exemplo n.º 51
0
        static void Main(string[] args)
        {
            try
            {
                Frog goshko = new Frog("Goshko", 10, "male");
                Frog peshko = new Frog("Peshko", 3, "male");
                Frog mariika = new Frog("Mariika", 7, "female");

                Dog ivancho = new Dog("Ivancho", 11, "male");
                Dog sashko = new Dog("Sashko", 1, "male");
                Dog magdalena = new Dog("Magdalena", 2, "female");

                Kitten tania = new Kitten("Tania", 3);
                Kitten penka = new Kitten("Penka", 4);
                Kitten goshka = new Kitten("Goshka", 10);

                Tomcat kristian = new Tomcat("Kristian", 1);
                Tomcat pesho = new Tomcat("Pesho", 10);
                Tomcat stanislav = new Tomcat("Stanislav", 5);

                IList<Animal> animals = new List<Animal>
                {
                    goshko, peshko, mariika, ivancho, sashko, magdalena,
                    tania, penka, goshka, kristian, pesho, stanislav
                };

                goshko.ProduceSound();
                sashko.ProduceSound();
                tania.ProduceSound();
                kristian.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);
            }
        }