Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            Dictionary <string, Dictionary <int, int> > dogs   = new Dictionary <string, Dictionary <int, int> >();
            Dictionary <string, Dictionary <int, int> > cats   = new Dictionary <string, Dictionary <int, int> >();
            Dictionary <string, Dictionary <int, int> > snakes = new Dictionary <string, Dictionary <int, int> >();

            string input = Console.ReadLine();

            while (!input.Equals("I'm your Huckleberry"))
            {
                string[] inputParts = input.Split(' ');

                if (inputParts[0].Equals("talk"))
                {
                    if (dogs.ContainsKey(inputParts[1]))
                    {
                        Dog.ProduceSound();
                    }
                    else if (cats.ContainsKey(inputParts[1]))
                    {
                        Cat.ProduceSound();
                    }
                    else if (snakes.ContainsKey(inputParts[1]))
                    {
                        Snake.ProduceSound();
                    }
                }
                else
                {
                    switch (inputParts[0])
                    {
                    case "Dog":
                        Dog dog = Dog.Parse(input);
                        dogs[dog.name]          = new Dictionary <int, int>();
                        dogs[dog.name][dog.age] = dog.numberOfLegs;
                        break;

                    case "Cat":
                        Cat cat = Cat.Parse(input);
                        cats[cat.name]          = new Dictionary <int, int>();
                        cats[cat.name][cat.age] = cat.intelligenceQuotient;
                        break;

                    case "Snake":
                        Snake snake = Snake.Parse(input);
                        snakes[snake.name]            = new Dictionary <int, int>();
                        snakes[snake.name][snake.age] = snake.crueltyCoefficient;
                        break;
                    }
                }

                input = Console.ReadLine();
            }

            DogsOutput(dogs);

            CatsOutput(cats);

            SnakesOutput(snakes);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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());
                }
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();
            string        cmd     = Console.ReadLine();

            while (cmd != "Beast!")
            {
                string[] tokens = Console.ReadLine()
                                  .Split(' ', StringSplitOptions.RemoveEmptyEntries);

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


                if (string.IsNullOrEmpty(name) ||
                    int.Parse(tokens[1]) < 0 ||
                    string.IsNullOrEmpty(gender))

                {
                    Console.WriteLine("Invalid input!");
                }
                else
                {
                    if (cmd == "Dog")
                    {
                        Dog current = new Dog(name, age, gender);
                        Console.WriteLine(current);
                        Console.WriteLine(current.ProduceSound());
                    }
                    else if (cmd == "Cat")
                    {
                        Cat currentCat = new Cat(name, age, gender);
                        Console.WriteLine(currentCat);
                        Console.WriteLine(currentCat.ProduceSound());
                    }
                    else if (cmd == "Frog")
                    {
                        Frog currentFrog = new Frog(name, age, gender);
                        Console.WriteLine(currentFrog);
                        Console.WriteLine(currentFrog.ProduceSound());
                    }
                    else if (cmd == "Tomcat")
                    {
                        Tomcat currentTom = new Tomcat(name, age);
                        Console.WriteLine(currentTom);
                        Console.WriteLine(currentTom.ProduceSound());
                    }
                    else if (cmd == "Kitten")
                    {
                        Kitten currentKitty = new Kitten(name, age);
                        Console.WriteLine(currentKitty);
                        Console.WriteLine(currentKitty.ProduceSound());
                    }
                }
                cmd = Console.ReadLine();
            }
        }
Ejemplo n.º 7
0
        public static void Main(string[] args)
        {
            while (true)
            {
                var line = System.Console.ReadLine();
                if (line == "Beast!")
                {
                    break;
                }
                var data   = System.Console.ReadLine().Split();
                var name   = data[0];
                var age    = int.Parse(data[1]);
                var gender = data[2];

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

                if (line == "Cat")
                {
                    var cat = new Cat(name, age, gender);

                    Console.WriteLine(cat);
                    cat.ProduceSound();
                }
                else if (line == "Dog")
                {
                    var dog = new Dog(name, age, gender);

                    Console.WriteLine(dog);
                    dog.ProduceSound();
                }
                else if (line == "Frog")
                {
                    var frog = new Frog(name, age, gender);

                    Console.WriteLine(frog);
                    frog.ProduceSound();
                }
                else if (line == "Tomcat")
                {
                    var tomcat = new Tomcat(name, age);

                    Console.WriteLine(tomcat);
                    tomcat.ProduceSound();
                }
                else if (line == "Kitten")
                {
                    var kitten = new Kitten(name, age);

                    Console.WriteLine(kitten);
                    kitten.ProduceSound();
                }
            }
        }
Ejemplo n.º 8
0
        public static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "Beast!")
                {
                    break;
                }


                string[] tokens = Console.ReadLine().Split();

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

                if (age < 0)
                {
                    Console.WriteLine("Invalid input!");
                    continue;
                }

                if (input == "Frog")
                {
                    Frog frog = new Frog(name, age, gender);
                    Console.WriteLine(frog);
                    frog.ProduceSound();
                }
                else if (input == "Dog")
                {
                    Dog dog = new Dog(name, age, gender);
                    Console.WriteLine(dog);
                    dog.ProduceSound();
                }
                else if (input == "Cat")
                {
                    Cat cat = new Cat(name, age, gender);
                    Console.WriteLine(cat);
                    cat.ProduceSound();
                }
                else if (input == "Tomcat")
                {
                    Tomcat tomcat = new Tomcat(name, age);
                    Console.WriteLine(tomcat);
                    tomcat.ProduceSound();
                }
                else if (input == "Kitten")
                {
                    Kitten kitten = new Kitten(name, age);
                    Console.WriteLine(kitten);
                    kitten.ProduceSound();
                }
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            while (true)
            {
                string   command = Console.ReadLine();
                string[] animals = Console.ReadLine().Split(" ").ToArray();
                string   name    = animals[0];
                int      age     = int.Parse(animals[1]);
                string   gender  = animals[2];

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

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


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

                else if (command == "Dog")
                {
                    var dog = new Dog(name, age, gender);
                    Console.WriteLine(dog);
                    Console.WriteLine(dog.ProduceSound());
                }
                else if (command == "Frog")
                {
                    var frog = new Frog(name, age, gender);
                    Console.WriteLine(frog);
                    Console.WriteLine(frog.ProduceSound());
                }
                else if (command == "Kittens")
                {
                    var kittens = new Kittens(name, age, gender);
                    Console.WriteLine(kittens);
                    Console.WriteLine(kittens.ProduceSound());
                }
                else if (command == "TomCat")
                {
                    var tomCat = new TomCat(name, age, gender);
                    Console.WriteLine(tomCat);
                    Console.WriteLine(tomCat.ProduceSound());
                }
            }
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            string input = string.Empty;

            while ((input = Console.ReadLine()) != "Beast!")
            {
                string[] tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

                string name   = tokens[0];
                int    age    = int.Parse(tokens[1]);
                string gender = tokens[2];
                try
                {
                    switch (input)
                    {
                    case "Dog":
                        Dog dog = new Dog(name, age, gender);
                        Console.WriteLine(dog);
                        dog.ProduceSound();
                        break;

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

                    case "Cat":
                        Cat cat = new Cat(name, age, gender);
                        Console.WriteLine(cat);
                        cat.ProduceSound();
                        break;

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

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(name, age);
                        Console.WriteLine(tomcat);
                        tomcat.ProduceSound();
                        break;

                    default:
                        throw new Exception("Invalid input!");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Ejemplo n.º 11
0
        public static void Main(string[] args)
        {
            while (true)
            {
                string line1 = Console.ReadLine();

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

                string[] data   = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   name   = data[0];
                int      age    = int.Parse(data[1]);
                string   gender = data[2];

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

                if (line1 == "Cat")
                {
                    Cat cat = new Cat(name, age, gender);
                    Console.WriteLine(cat);
                    Console.WriteLine(cat.ProduceSound());
                }
                else if (line1 == "Dog")
                {
                    Dog dog = new Dog(name, age, gender);
                    Console.WriteLine(dog);
                    Console.WriteLine(dog.ProduceSound());
                }
                else if (line1 == "Frog")
                {
                    Frog frog = new Frog(name, age, gender);
                    Console.WriteLine(frog);
                    Console.WriteLine(frog.ProduceSound());
                }
                else if (line1 == "Tomcat")
                {
                    Tomcat tomcat = new Tomcat(name, age);
                    Console.WriteLine(tomcat);
                    Console.WriteLine(tomcat.ProduceSound());
                }
                else if (line1 == "Kitten")
                {
                    Kitten kitten = new Kitten(name, age);
                    Console.WriteLine(kitten);
                    Console.WriteLine(kitten.ProduceSound());
                }
            }
        }
Ejemplo n.º 12
0
        public static void Main(string[] args)
        {
            string type = Console.ReadLine();

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

                if (int.Parse(animalInfo[1]) < 0 || string.IsNullOrEmpty(animalInfo[2]) || string.IsNullOrEmpty(animalInfo[0]))
                {
                    Console.WriteLine("Invalid input!");
                    continue;
                }

                if (type == "Cat")
                {
                    Cat cat = new Cat(animalInfo[0], int.Parse(animalInfo[1]), animalInfo[2]);

                    Console.WriteLine(cat);
                    Console.WriteLine(cat.ProduceSound());
                }
                else if (type == "Dog")
                {
                    Dog dog = new Dog(animalInfo[0], int.Parse(animalInfo[1]), animalInfo[2]);

                    Console.WriteLine(dog);
                    Console.WriteLine(dog.ProduceSound());
                }
                else if (type == "Frog")
                {
                    Frog frog = new Frog(animalInfo[0], int.Parse(animalInfo[1]), animalInfo[2]);

                    Console.WriteLine(frog);
                    Console.WriteLine(frog.ProduceSound());
                }
                else if (type == "Kitten")
                {
                    Kitten kitten = new Kitten(animalInfo[0], int.Parse(animalInfo[1]));

                    Console.WriteLine(kitten);
                    Console.WriteLine(kitten.ProduceSound());
                }
                else if (type == "Tomcat")
                {
                    Tomcat tomcat = new Tomcat(animalInfo[0], int.Parse(animalInfo[1]));

                    Console.WriteLine(tomcat);
                    Console.WriteLine(tomcat.ProduceSound());
                }

                type = Console.ReadLine();
            }
        }
        public static void Main(string[] args)
        {
            string animalType = Console.ReadLine();

            while (animalType != "Beast!")
            {
                try
                {
                    var animalInfo = Console.ReadLine()
                                     .Split(" ")
                                     .ToArray();


                    if (animalType == "Cat")
                    {
                        Cat cat = new Cat(animalInfo[0], int.Parse(animalInfo[1]), animalInfo[2]);
                        Console.WriteLine(cat);
                        Console.WriteLine(cat.ProduceSound());
                    }
                    else if (animalType == "Tomcat")
                    {
                        Tomcat tomcat = new Tomcat(animalInfo[0], int.Parse(animalInfo[1]));
                        Console.WriteLine(tomcat);
                        Console.WriteLine(tomcat.ProduceSound());
                    }
                    else if (animalType == "Kitten")
                    {
                        Kitten kitten = new Kitten(animalInfo[0], int.Parse(animalInfo[1]));
                        Console.WriteLine(kitten);
                        Console.WriteLine(kitten.ProduceSound());
                    }
                    else if (animalType == "Dog")
                    {
                        Dog dog = new Dog(animalInfo[0], int.Parse(animalInfo[1]), animalInfo[2]);
                        Console.WriteLine(dog);
                        Console.WriteLine(dog.ProduceSound());
                    }
                    else if (animalType == "Frog")
                    {
                        Frog frog = new Frog(animalInfo[0], int.Parse(animalInfo[1]), animalInfo[2]);
                        Console.WriteLine(frog);
                        Console.WriteLine(frog.ProduceSound());
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }

                animalType = Console.ReadLine();
            }
        }
Ejemplo n.º 14
0
        public static void Main(string[] args)
        {
            string type;

            while ((type = Console.ReadLine()) != "Beast!")
            {
                string comand = Console.ReadLine();

                var comandArgs = comand.Split();
                var name       = comandArgs[0];
                var age        = int.Parse(comandArgs[1]);
                var gender     = comandArgs[2];

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

                if (type == "Dog")
                {
                    Dog dog = new Dog(name, age, gender);
                    Console.WriteLine(dog.ToString());
                    dog.ProduceSound();
                }
                else if (type == "Cat")
                {
                    Cat cat = new Cat(name, age, gender);
                    Console.WriteLine(cat.ToString());
                    cat.ProduceSound();
                }
                else if (type == "Frog")
                {
                    Frog frog = new Frog(name, age, gender);
                    Console.WriteLine(frog.ToString());
                    frog.ProduceSound();
                }
                else if (type == "Kittens")
                {
                    Kitten kit = new Kitten(name, age);
                    Console.WriteLine(kit.ToString());
                    kit.ProduceSound();
                }
                else if (type == "Tomcat")
                {
                    Tomcat tom = new Tomcat(name, age);
                    Console.WriteLine(tom.ToString());
                    tom.ProduceSound();
                }
            }
        }
Ejemplo n.º 15
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();
        }
Ejemplo n.º 16
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();
        }
Ejemplo n.º 17
0
        public static void Main(string[] args)
        {
            // input
            string input = string.Empty;

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

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

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

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

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

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

                else if (input == "Tomcat")
                {
                    var tomcat = new Tomcat(name, age);
                    Console.WriteLine(tomcat.ProduceSound());
                }
            }
        }
Ejemplo n.º 18
0
        public static void Main(string[] args)
        {
            string input = Console.ReadLine();

            while (input != "Beast!")
            {
                if (input == "Cat")
                {
                    string[] tokens = Console.ReadLine().Split();
                    Cat      cat    = new Cat(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    Console.WriteLine(cat);
                    Console.WriteLine(cat.ProduceSound());
                }
                else if (input == "Frog")
                {
                    string[] tokens = Console.ReadLine().Split();
                    Frog     frog   = new Frog(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    Console.WriteLine(frog);
                    Console.WriteLine(frog.ProduceSound());
                }
                else if (input == "Dog")
                {
                    string[] tokens = Console.ReadLine().Split();
                    Dog      dog    = new Dog(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    Console.WriteLine(dog);
                    Console.WriteLine(dog.ProduceSound());
                }
                else if (input == "Tomcat")
                {
                    string[] tokens = Console.ReadLine().Split();
                    Tomcat   tomcat = new Tomcat(tokens[0], int.Parse(tokens[1]));
                    Console.WriteLine(tomcat);
                    Console.WriteLine(tomcat.ProduceSound());
                }
                else if (input == "Kitten")
                {
                    string[] tokens = Console.ReadLine().Split();
                    Kitten   kitten = new Kitten(tokens[0], int.Parse(tokens[1]));
                    Console.WriteLine(kitten);
                    Console.WriteLine(kitten.ProduceSound());
                }
                input = Console.ReadLine();
            }
        }
Ejemplo n.º 19
0
        private static void CreateAnimal(string animalType)
        {
            string[] input  = Console.ReadLine().Split();
            string   name   = input[0];
            int      age    = int.Parse(input[1]);
            string   gender = input[2];

            switch (animalType)
            {
            case "Dog":
                Dog dog = new Dog(name, age, gender);
                Console.WriteLine(dog);
                dog.ProduceSound();
                break;

            case "Cat":
                Cat cat = new Cat(name, age, gender);
                Console.WriteLine(cat);
                cat.ProduceSound();
                break;

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

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

            case "Tomcat":
                Tomcat tomcat = new Tomcat(name, age, gender);
                Console.WriteLine(tomcat);
                tomcat.ProduceSound();
                break;

            default:
                throw new ArgumentException(Animal.ERROR_MESSAGE);
            }
        }
        static void Main()
        {
            Animal jaba     = new Frog("baba jaba", 1, Genders.Female);
            Animal kekerica = new Frog("kikirica", 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);

            Animal[] animals = new 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 animalLine
                                 select new { GroupName = animalLine.Key, AverageAge = animalLine.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();
        }
Ejemplo n.º 21
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();
        }
        public void Run()
        {
            string animal = Console.ReadLine();

            string[] properties = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

            while (true)
            {
                string name   = properties[0];
                int    age    = int.Parse(properties[1]);
                string gender = string.Empty;

                if (age <= 0)
                {
                    Console.WriteLine("Invalid input!");


                    animal = Console.ReadLine();

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

                    properties = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

                    continue;
                }

                if (properties.Length > 2)
                {
                    gender = properties[2];
                }

                switch (animal)
                {
                case "Cat":
                {
                    Console.WriteLine(animal);
                    Cat cat = new Cat(name, age, gender);
                    Console.WriteLine(cat);
                    Console.WriteLine(cat.ProduceSound());
                }
                break;

                case "Dog":
                {
                    Dog dog = new Dog(name, age, gender);
                    Console.WriteLine(animal);
                    Console.WriteLine(dog);
                    Console.WriteLine(dog.ProduceSound());
                }
                break;

                case "Frog":
                {
                    Console.WriteLine(animal);
                    Frog frog = new Frog(name, age, gender);
                    Console.WriteLine(frog);
                    Console.WriteLine(frog.ProduceSound());
                }
                break;

                case "Tomcat":
                {
                    Console.WriteLine(animal);
                    Tomcat tomcat = new Tomcat(name, age);
                    Console.WriteLine(tomcat);
                    Console.WriteLine(tomcat.ProduceSound());
                }
                break;

                case "Kitten":
                {
                    Console.WriteLine(animal);
                    Kitten kitten = new Kitten(name, age);
                    Console.WriteLine(kitten);
                    Console.WriteLine(kitten.ProduceSound());
                }
                break;
                }
                animal = Console.ReadLine();

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

                properties = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            }
        }
Ejemplo n.º 23
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();
        }
Ejemplo n.º 24
0
        static void Main()
        {
            var animal = Console.ReadLine();

            while (!animal.Equals("Beast!"))
            {
                try
                {
                    var animalInfo = Console.ReadLine()
                                     .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    var animalName   = animalInfo[0];
                    var animalAge    = int.Parse(animalInfo[1]);
                    var animalGender = animalInfo[2];

                    switch (animal)
                    {
                    case "Dog":
                        var dog = new Dog(animalName, animalAge, animalGender);
                        Console.Write(dog);
                        dog.ProduceSound();
                        break;

                    case "Frog":
                        var frog = new Frog(animalName, animalAge, animalGender);
                        Console.Write(frog);
                        frog.ProduceSound();
                        break;

                    case "Cat":
                        var cat = new Cat(animalName, animalAge, animalGender);
                        Console.Write(cat);
                        cat.ProduceSound();
                        break;

                    case "Kitten":
                        var kitten = new Kitten(animalName, animalAge, "Female");
                        Console.Write(kitten);
                        kitten.ProduceSound();
                        break;

                    case "Tomcat":
                        var tomcat = new Tomcat(animalName, animalAge, "Male");
                        Console.Write(tomcat);
                        tomcat.ProduceSound();
                        break;

                    case "Animal":
                        Console.WriteLine("Not implemented!");
                        break;

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

                animal = Console.ReadLine();
            }
        }
Ejemplo n.º 25
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);
            }
        }
Ejemplo n.º 26
0
        public static void Main()
        {
            var animal = new Dog("pesho", 22, "Male");

            Console.WriteLine(animal.ProduceSound());
        }
Ejemplo n.º 27
0
        public static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    var animal = Console.ReadLine();

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

                    var animaInfo = Console.ReadLine().Split(" ");

                    var name = animaInfo[0];
                    int age;
                    if (!int.TryParse(animaInfo[1], out age))
                    {
                        throw new ArgumentException("Invalid input!");
                    }
                    var gender = animaInfo[2];

                    if (animal == "Cat")
                    {
                        Console.WriteLine(animal);
                        Cat cat = new Cat(name, age, gender);
                        Console.WriteLine(cat);
                        cat.ProduceSound();
                    }
                    else if (animal == "Dog")
                    {
                        Console.WriteLine(animal);
                        Dog dog = new Dog(name, age, gender);
                        Console.WriteLine($"{dog}");
                        dog.ProduceSound();
                    }
                    else if (animal == "Frog")
                    {
                        Console.WriteLine(animal);
                        Frog frog = new Frog(name, age, gender);
                        Console.WriteLine(frog);
                        frog.ProduceSound();
                    }
                    else if (animal == "Kitten")
                    {
                        Console.WriteLine(animal);
                        Kitten kitten = new Kitten(name, age);
                        Console.WriteLine($"{kitten}");
                        kitten.ProduceSound();
                    }
                    else if (animal == "Tomcat")
                    {
                        Console.WriteLine(animal);
                        Tomcat tomcat = new Tomcat(name, age);
                        Console.WriteLine($"{tomcat}");
                        tomcat.ProduceSound();
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }