// Main logic. public void Run() { string command; while ((command = Console.ReadLine()) != "Beast!") { try { var type = command; var data = Console.ReadLine().Split(); var name = data[0]; var age = int.Parse(data[1]); var gender = data[2]; var animal = animalFactory.CreateAnimal(type, name, age, gender); animals.Add(animal); } catch (Exception ex) { Console.WriteLine(ex.Message); } } Print(); }
public void Run() { string input = Console.ReadLine(); while (input != "Beast!") { try { string animalType = input; string[] animalTokens = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); string name = animalTokens[0]; int age = int.Parse(animalTokens[1]); string gender = animalTokens[2]; Animal animal = animalFactory.CreateAnimal(animalType, name, age, gender); animals.Add(animal); } catch (Exception ex) { Console.WriteLine(ex.Message); } input = Console.ReadLine(); } Print(); }
public void Run() { while (true) { string input = Console.ReadLine(); if (input == "Beast!") { break; } try { string type = input; string[] data = Console.ReadLine().Split(); string name = data[0]; int age = int.Parse(data[1]); string gender = data[2]; Animal animal = animalFactory.CreateAnimal(type, name, age, gender); animals.Add(animal); } catch (Exception ex) { Console.WriteLine(ex.Message); } } Print(); }
public void Run() { string input = Console.ReadLine(); while (input != "Beast!") { try { string type = input; string[] data = Console.ReadLine() .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string name = data[0]; int age = int.Parse(data[1]); string gender = data[2]; Animal animal = animalFactory.CreateAnimal(type, name, age, gender); animals.Add(animal); } catch (Exception ex) { Console.WriteLine(ex.Message); } input = Console.ReadLine(); } Print(); }
public void Run() { string type = Console.ReadLine(); while (type.Equals("Beast!") == false) { try { string[] token = Console.ReadLine() .Split(); string name = token[0]; int age = int.Parse(token[1]); string gender = token[2]; Animal animal = animalFactory .CreateAnimal(type, name, age, gender); animals.Add(animal); } catch (Exception ex) { Console.WriteLine(ex.Message); } type = Console.ReadLine(); } Print(); }
public void Run() { string input = Console.ReadLine(); while (!input.Equals("Beast!")) { try { string[] arguments = Console.ReadLine().Split(); string name = arguments[0]; int? age = int.Parse(arguments[1]); string gender = arguments[2]; var newAnimal = animalFactory.CreateAnimal(input, name, age, gender); animals.Add(newAnimal); } catch (Exception ex) { Console.WriteLine(ex.Message); } input = Console.ReadLine(); } foreach (var animal in animals) { Console.WriteLine(animal); Console.WriteLine($"{animal.Name} {animal.Age} {animal.Gender}"); animal.ProduceSound(); } }
public void Run() { while (true) { string input = Console.ReadLine(); if (input == "Beast!") { break; } string[] args = Console.ReadLine().Split().ToArray(); string type = input; string name = args[0]; int age = int.Parse(args[1]); string gender = args[2]; Animal animal; try { animal = animalfactory.CreateAnimal(type, name, age, gender); } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } animals.Add(animal); } foreach (var animal in animals) { Console.WriteLine(animal.ToString()); } }
public void Run() { string inputTypeAnimal; while ((inputTypeAnimal = Console.ReadLine()) != "Beast!") { try { string[] inputAnimalInfo = Console.ReadLine().Split(); string name = inputAnimalInfo[0]; int age = int.Parse(inputAnimalInfo[1]); string gender = inputAnimalInfo[2]; Animal animal = animalFactory.CreateAnimal(inputTypeAnimal, name, age, gender); animals.Add(animal); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } Print(); }