public void Run()
        {
            string input = Console.ReadLine();

            while (input.ToLower() != "beast!")
            {
                try
                {
                    string   animalType = input;
                    string[] animalInfo = Console.ReadLine()
                                          .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                          .ToArray();
                    Animal animal = animalFactory.CreateAnimal(
                        animalType,
                        animalInfo[0],
                        int.Parse(animalInfo[1]),
                        animalInfo[2]);
                    Console.WriteLine(animal);
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
                input = Console.ReadLine();
            }
        }
Exemple #2
0
        public void Run()
        {
            string typeAnimal = string.Empty;

            while ((typeAnimal = Console.ReadLine()) != "Beast!")
            {
                try
                {
                    if (typeAnimal.Length == 0)
                    {
                        throw new ArgumentException();
                    }

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

                    if (animalInfo.Length < 3)
                    {
                        throw new ArgumentException();
                    }

                    var newFactory = new AnimalFactory(animalInfo, typeAnimal);
                    myList.Add(newFactory.CreateAnimal());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid input!");
                }
            }

            Printing();
        }
Exemple #3
0
        public void Run()
        {
            AnimalFactory af = new AnimalFactory();
            string        input;

            while ((input = Console.ReadLine()) != "Beast!")
            {
                var    args = Console.ReadLine().Split();
                string type = input;
                animals.Add(af.CreateAnimal(type, args));
            }
            Print();
        }
        public static void Main()
        {
            string type;

            while ((type = Console.ReadLine()) != "Beast!")
            {
                var    args    = Console.ReadLine().Split();
                Animal newType = null;
                try
                {
                    newType = AnimalFactory.CreateAnimal(type, args);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                if (newType != null)
                {
                    Console.WriteLine(newType);
                }
            }
        }