Beispiel #1
0
        static void Main()
        {
            List <Animal> animals = new List <Animal>();

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                Animal animal = AnimalFactory.Create(command.Split(' ', StringSplitOptions.RemoveEmptyEntries));
                animals.Add(animal);

                Console.WriteLine(animal.ProducieSound());
                Food food = FoodFactory.Create(Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries));

                try
                {
                    animal.CheckFoodType(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            animals.ForEach(Console.WriteLine);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            FoodFactory   foodFactory   = new FoodFactory();
            AnimalFactory animalFactory = new AnimalFactory();
            List <Animal> animals       = new List <Animal>();

            string input = Console.ReadLine();

            while (input != "End")
            {
                string[] animalArgs = input
                                      .Split();

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

                string foodType   = foodArgs[0];
                int    foodWeight = int.Parse(foodArgs[1]);

                Food   food   = foodFactory.Create(foodType, foodWeight);
                Animal animal = animalFactory.Create(animalArgs);

                Console.WriteLine(animal.ProduceSound());
                try
                {
                    animal.Eat(foodType, foodWeight);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animals.Add(animal);
                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            while (true)
            {
                string line = Console.ReadLine();

                if (line == "End")
                {
                    break;
                }

                string[] animalArgs = line.Split();

                Animal animal = AnimalFactory.Create(animalArgs);

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

                Food food = FoodFactory.Create(foodArgs);

                Console.WriteLine(animal.ProduceSound());

                try
                {
                    animal.Eat(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Beispiel #4
0
        public static void Main()
        {
            string input = Console.ReadLine();

            List <Animal> animals = new List <Animal>();

            while (input != "End")
            {
                string[] animalArgs = input
                                      .Split();

                Animal animal = AnimalFactory.Create(animalArgs);

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

                Food food = FoodFactory.Create(foodArgs);

                Console.WriteLine(animal.ProduceSound());

                try
                {
                    animal.Eat(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                animals.Add(animal);

                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }