static void Main(string[] args)
        {
            Animal animal = new Cat("Mimi",4,Gender.female);
            Animal animal1 = new Dog("Sharo", 1, Gender.female);
            Animal animal2 = new Frog("Kikirica", 5, Gender.female);
            Animal animal3 = new Kitten("Mimi", 7);
            Animal animal4 = new Tomcat("Mimi", 5);
            Animal animal5 = new Frog("Mimi", 4, Gender.female);

            Animal[] zoo = new Animal[]{
            animal,animal1,animal2,animal3,animal4,animal
            };
            var avarageAge = zoo.Average(a=>a.Age);
            Console.WriteLine("{0:0.00}",avarageAge);
        }
 public Tomcat(Cat inputAnimal)
     : base(inputAnimal)
 {
     base.sexMale = true;
 }
 public Kitten(Cat inputAnimal)
     : base(inputAnimal)
 {
     base.sexMale = false;
 }
예제 #4
0
        static void Main()
        {
            var dogs   = new Dictionary <string, Dog>();
            var cats   = new Dictionary <string, Cat>();
            var snakes = new Dictionary <string, Snake>();

            string input = Console.ReadLine();

            while (input != "I'm your Huckleberry")
            {
                string[] inputTokens = input.Split(' ');
                string   type        = inputTokens[0];

                if (type == "talk")
                {
                    string name = inputTokens[1];

                    if (dogs.ContainsKey(name))
                    {
                        dogs[name].ProduceSound();
                    }
                    else if (cats.ContainsKey(name))
                    {
                        cats[name].ProduceSound();
                    }
                    else
                    {
                        snakes[name].ProduceSound();
                    }
                }
                else
                {
                    string name  = inputTokens[1];
                    int    age   = int.Parse(inputTokens[2]);
                    int    param = int.Parse(inputTokens[3]);

                    if (type == "Dog")
                    {
                        dogs.Add(name, new Dog(name, age, param));
                    }
                    else if (type == "Cat")
                    {
                        cats.Add(name, new Cat(name, age, param));
                    }
                    else
                    {
                        snakes.Add(name, new Snake(name, age, param));
                    }
                }

                input = Console.ReadLine();
            }

            foreach (var dogData in dogs)
            {
                Dog dog = dogData.Value;
                Console.WriteLine("Dog: {0}, Age: {1}, Number Of Legs: {2}",
                                  dog.Name, dog.Age, dog.LegsCount);
            }

            foreach (var catData in cats)
            {
                Cat cat = catData.Value;
                Console.WriteLine("Cat: {0}, Age: {1}, IQ: {2}",
                                  cat.Name, cat.Age, cat.IQ);
            }

            foreach (var snakeData in snakes)
            {
                Snake snake = snakeData.Value;
                Console.WriteLine("Snake: {0}, Age: {1}, Cruelty: {2}",
                                  snake.Name, snake.Age, snake.Cruelty);
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            List <Dog>   dogs   = new List <Dog>();
            List <Cat>   cats   = new List <Cat>();
            List <Snake> snakes = new List <Snake>();


            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                if (input[0] == "I'm" && input[1] == "your" && input[2] == "Huckleberry")
                {
                    break;
                }

                if (input.Length > 2)
                {
                    var clas = input[0];
                    var nam  = input[1];
                    var age  = int.Parse(input[2]);
                    var iq   = int.Parse(input[3]);

                    if (clas == "Dog")
                    {
                        var newDog = new Dog()
                        {
                            Name         = nam,
                            Age          = age,
                            NumberOfLegs = iq
                        };
                        dogs.Add(newDog);
                    }
                    else if (clas == "Cat")
                    {
                        var newCat = new Cat()
                        {
                            Name = nam,
                            Age  = age,
                            IntelligenceQuotient = iq
                        };
                        cats.Add(newCat);
                    }
                    else if (clas == "Snake")
                    {
                        var newSnake = new Snake()
                        {
                            Name = nam,
                            Age  = age,
                            CrueltyCoefficient = iq
                        };
                        snakes.Add(newSnake);
                    }
                }
                else
                {
                    foreach (var dog in dogs)
                    {
                        if (input[1].Contains(dog.Name))
                        {
                            Console.WriteLine("I'm a Distinguishedog, and I will now produce a distinguished sound! Bau Bau.");
                            break;
                        }
                    }
                    foreach (var cat in cats)
                    {
                        if (input[1].Contains(cat.Name))
                        {
                            Console.WriteLine("I'm an Aristocat, and I will now produce an aristocratic sound! Myau Myau.");
                            break;
                        }
                    }
                    foreach (var snake in snakes)
                    {
                        if (input[1].Contains(snake.Name))
                        {
                            Console.WriteLine("I'm a Sophistisnake, and I will now produce a sophisticated sound! Honey, I'm home.");
                        }
                    }
                }
            }
            foreach (var dog in dogs)
            {
                Console.WriteLine($"Dog: {dog.Name}, Age: {dog.Age}, Number Of Legs: {dog.NumberOfLegs}");
            }
            foreach (var cat in cats)
            {
                Console.WriteLine($"Cat: {cat.Name}, Age: {cat.Age}, IQ: {cat.IntelligenceQuotient}");
            }
            foreach (var snake in snakes)
            {
                Console.WriteLine($"Snake: {snake.Name}, Age: {snake.Age}, Cruelty: {snake.CrueltyCoefficient}");
            }
        }
예제 #6
0
        static void Main()
        {
            Dictionary <string, Animal> animals = new Dictionary <string, Animal>();
            List <Dog>   dogs   = new List <Dog>();
            List <Cat>   cats   = new List <Cat>();
            List <Snake> snakes = new List <Snake>();
            string       input  = Console.ReadLine();

            while (input != "I'm your Huckleberry")
            {
                string[] inputs = input.Split(' ');
                if (inputs[0] == "talk")
                {
                    if (animals.ContainsKey(inputs[1]))
                    {
                        Animal a = animals[inputs[1]];
                        a.ProduceSound();
                    }
                }
                else
                {
                    string className          = inputs[0];
                    string name               = string.Join(" ", inputs.Skip(1).Take(inputs.Length - 3));
                    int    age                = int.Parse(inputs.Skip(inputs.Length - 2).First());
                    int    dependentFromClass = int.Parse(inputs.Skip(inputs.Length - 1).First());
                    switch (className)
                    {
                    case "Dog":
                        Dog d = new Dog(name, age, dependentFromClass);
                        animals.Add(name, d);
                        dogs.Add(d);
                        break;

                    case "Snake":
                        Snake s = new Snake(name, age, dependentFromClass);
                        animals.Add(name, s);
                        snakes.Add(s);
                        break;

                    case "Cat":
                        Cat c = new Cat(name, age, dependentFromClass);
                        animals.Add(name, c);
                        cats.Add(c);
                        break;
                    }
                }
                input = Console.ReadLine();
            }
            foreach (var dog in dogs)
            {
                Console.WriteLine($"Dog: {dog.Name}, Age: {dog.Age}, Number Of Legs: {dog.NumberOfLegs}");
            }
            foreach (var cat in cats)
            {
                Console.WriteLine($"Cat: {cat.Name}, Age: {cat.Age}, IQ: {cat.Iq}");
            }
            foreach (var lady in snakes)
            {
                Console.WriteLine($"Snake: {lady.Name}, Age: {lady.Age}, Cruelty: {lady.CrueltyCoefficient}");
            }
        }
        public static void Main()
        {
            Dictionary <string, Dog>   dogs   = new Dictionary <string, Dog>();
            Dictionary <string, Cat>   cats   = new Dictionary <string, Cat>();
            Dictionary <string, Snake> snakes = new Dictionary <string, Snake>();

            string inputLine = Console.ReadLine();

            while (inputLine != "I'm your Huckleberry")
            {
                string[] tokens = inputLine.Split(' ');

                if (tokens.Length > 2)
                {
                    string type      = tokens[0];
                    string name      = tokens[1];
                    int    age       = int.Parse(tokens[2]);
                    int    parameter = int.Parse(tokens[3]);

                    switch (type)
                    {
                    case "Dog":
                        Dog newDog = new Dog();
                        newDog.Name         = name;
                        newDog.Age          = age;
                        newDog.NumberOfLegs = parameter;

                        dogs.Add(newDog.Name, newDog);
                        break;

                    case "Cat":
                        Cat newCat = new Cat();
                        newCat.Name = name;
                        newCat.Age  = age;
                        newCat.IntelligenceQuotient = parameter;

                        cats.Add(newCat.Name, newCat);
                        break;

                    case "Snake":
                        Snake newSnake = new Snake();
                        newSnake.Name = name;
                        newSnake.Age  = age;
                        newSnake.CrueltyCoefficient = parameter;

                        snakes.Add(newSnake.Name, newSnake);
                        break;
                    }
                }
                else
                {
                    string animalName = tokens[1];

                    if (dogs.ContainsKey(animalName))
                    {
                        dogs[animalName].ProduceSound();
                    }
                    else if (cats.ContainsKey(animalName))
                    {
                        cats[animalName].ProduceSound();
                    }
                    else if (snakes.ContainsKey(animalName))
                    {
                        snakes[animalName].ProduceSound();
                    }
                }

                inputLine = Console.ReadLine();
            }

            foreach (var dog in dogs.Values)
            {
                Console.WriteLine(
                    $"Dog: {dog.Name}, Age: {dog.Age}, Number Of Legs: {dog.NumberOfLegs}");
            }

            foreach (var cat in cats.Values)
            {
                Console.WriteLine(
                    $"Cat: {cat.Name}, Age: {cat.Age}, IQ: {cat.IntelligenceQuotient}");
            }

            foreach (var snake in snakes.Values)
            {
                Console.WriteLine(
                    $"Snake: {snake.Name}, Age: {snake.Age}, Cruelty: {snake.CrueltyCoefficient}");
            }
        }
예제 #8
0
        public static void Main()
        {
            var dogs   = new List <Dog>();
            var cats   = new List <Cat>();
            var snakes = new List <Snake>();

            var entered = Console.ReadLine();

            while (entered != "I'm your Huckleberry")
            {
                var parameters = entered.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();

                var kind     = parameters[0];
                var name     = parameters[1];
                var age      = string.Empty;
                var property = string.Empty;;

                if (parameters.Count > 2)
                {
                    age      = parameters[2];
                    property = parameters[3];
                }

                if (kind == "Dog")
                {
                    var newDog = new Dog();
                    {
                        newDog.Class = kind;
                        newDog.Name  = name;
                        newDog.Age   = age;
                        newDog.Legs  = property;
                    }
                    dogs.Add(newDog);
                }
                else if (kind == "Cat")
                {
                    var newCat = new Cat();
                    {
                        newCat.Class = kind;
                        newCat.Name  = name;
                        newCat.Age   = age;
                        newCat.IQ    = property;
                    }
                    cats.Add(newCat);
                }
                else if (kind == "Snake")
                {
                    var newSnake = new Snake();
                    {
                        newSnake.Class   = kind;
                        newSnake.Name    = name;
                        newSnake.Age     = age;
                        newSnake.Cruelty = property;
                    }
                    snakes.Add(newSnake);
                }
                else
                {
                    foreach (var item in dogs)
                    {
                        if (item.Name == name)
                        {
                            Console.WriteLine(Dog.ProduceSound());
                        }
                    }
                    foreach (var item in cats)
                    {
                        if (item.Name == name)
                        {
                            Console.WriteLine(Cat.ProduceSound());
                        }
                    }
                    foreach (var item in snakes)
                    {
                        if (item.Name == name)
                        {
                            Console.WriteLine(Snake.ProduceSound());
                        }
                    }
                }

                entered = Console.ReadLine();
            }

            foreach (var item in dogs)
            {
                Console.WriteLine($"{item.Class}: {item.Name}, Age: {item.Age}, Number Of Legs: {item.Legs}");
            }
            foreach (var item in cats)
            {
                Console.WriteLine($"{item.Class}: {item.Name}, Age: {item.Age}, IQ: {item.IQ}");
            }
            foreach (var item in snakes)
            {
                Console.WriteLine($"{item.Class}: {item.Name}, Age: {item.Age}, Cruelty: {item.Cruelty}");
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            Dog dog = new Dog("sharo", AnimalSex.male, 18);
            Console.WriteLine(dog.ToString());

            Frog frog = new Frog("Kermit", AnimalSex.male, 20);
            Console.WriteLine(frog.ToString());

            Cat regularCat = new Cat("CAT", AnimalSex.female, 4);
            Console.WriteLine(regularCat.ToString());

            Kitten kitten = new Kitten("kittie", AnimalSex.female, 1);
            //Kitten kitten = new Kitten("kittie", AnimalSex.male, 1); - this will explode
            Console.WriteLine(kitten.ToString());

            Tomcat tomcat = new Tomcat("Topcat", AnimalSex.male, 2);
            //Tomcat tomcat = new Tomcat("Topcat", AnimalSex.female, 2); - this too will explode
            Console.WriteLine(tomcat.ToString());

            //sounds
            Console.WriteLine();
            Console.WriteLine(dog.ProduceSound());
            Console.WriteLine(frog.ProduceSound());
            Console.WriteLine(regularCat.ProduceSound());
            Console.WriteLine(kitten.ProduceSound());
            Console.WriteLine(tomcat.ProduceSound());
            Console.WriteLine();

            List<Dog> dogs = new List<Dog>();
            dogs.Add(dog);
            dogs.Add(new Dog("me4o", AnimalSex.female, 69));
            dogs.Add(new Dog("FU", AnimalSex.female, 96));
            double averageAge = dogs.Average((x) => x.Age);
            Console.WriteLine("Dogs average age: {0}", averageAge);

            List<Frog> frogs = new List<Frog>();
            frogs.Add(frog);
            frogs.Add(new Frog("Big Toad", AnimalSex.male, 2));
            frogs.Add(new Frog("Lesser Toad", AnimalSex.female, 2));
            averageAge = frogs.Average((x) => x.Age);
            Console.WriteLine("Frogs average age: {0}", averageAge);

            List<Kitten> kittens = new List<Kitten>();
            kittens.Add(kitten);
            kittens.Add(new Kitten("little kittenn", AnimalSex.female, 2));
            kittens.Add(new Kitten("big kitten", AnimalSex.female, 2));
            averageAge = kittens.Average((x) => x.Age);
            Console.WriteLine("Kittens average age: {0}", averageAge);
        }