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); }
private static void AddAnimal(string inputLine, List <Dog> dogs, List <Cat> cats, List <Snake> snakes, string type) { if (type == "Dog") { var currentDog = Dog.Parse(inputLine); dogs.Add(currentDog); } else if (type == "Cat") { var currentCat = Cat.Parse(inputLine); cats.Add(currentCat); } else if (type == "Snake") { var currentSnake = Snake.Parse(inputLine); snakes.Add(currentSnake); } }