Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var animals = new List <Animal>();

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

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

                var    data       = cmd.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string animalType = data[0];
                string name       = data[1];
                double weight     = double.Parse(data[2]);

                Animal animal = null;

                switch (animalType)
                {
                case "Owl":
                {
                    int wingSize = int.Parse(data[3]);

                    animal = new Owl(name, weight, wingSize);
                    break;
                }

                case "Hen":
                {
                    int wingSize = int.Parse(data[3]);

                    animal = new Hen(name, weight, wingSize);
                    break;
                }

                case "Mouse":
                {
                    string region = data[3];

                    animal = new Mouse(name, weight, region);
                    break;
                }

                case "Dog":
                {
                    string region = data[3];

                    animal = new Dog(name, weight, region);
                    break;
                }

                case "Cat":
                {
                    string region = data[3];
                    string breed  = data[4];

                    animal = new Cat(name, weight, region, breed);
                    break;
                }

                case "Tiger":
                {
                    string region = data[3];
                    string breed  = data[4];

                    animal = new Tiger(name, weight, region, breed);
                    break;
                }

                default:
                    break;
                }

                Console.WriteLine(animal.ProduceSound());

                var foodData = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string foodName = foodData[0];
                int    foodNum  = int.Parse(foodData[1]);

                Food food = null;

                switch (foodName)
                {
                case "Fruit":
                {
                    food = new Fruit(foodNum);

                    break;
                }

                case "Meat":
                {
                    food = new Meat(foodNum);
                    break;
                }

                case "Seeds":
                {
                    food = new Seeds(foodNum);
                    break;
                }

                case "Vegetable":
                {
                    food = new Vegetable(foodNum);
                    break;
                }

                default:
                    break;
                }

                animal.Feed(food);
                animals.Add(animal);
            }

            foreach (var beast in animals)
            {
                Console.WriteLine(beast.ToString());
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var animalsCollect = new List <Animal>();

            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] animal = input.Split();
                string   type   = animal[0];
                string   name   = animal[1];
                double   weight = double.Parse(animal[2]);

                string[] foods    = Console.ReadLine().Split();
                string   typeFood = foods[0];
                int      quantity = int.Parse(foods[1]);

                Animal animals = null;
                switch (type)
                {
                case "Cat":
                    string livingRegionCat = animal[3];
                    string breedCat        = animal[4];
                    animals = new Cat(name, weight, livingRegionCat, breedCat);
                    break;

                case "Tiger":
                    string livingRegionTiger = animal[3];
                    string breedTiger        = animal[4];
                    animals = new Tiger(name, weight, livingRegionTiger, breedTiger);
                    break;

                case "Dog":
                    string livingRegionDog = animal[3];
                    animals = new Dog(name, weight, livingRegionDog);
                    break;

                case "Mouse":
                    string livingRegionMouse = animal[3];
                    animals = new Mouse(name, weight, livingRegionMouse);
                    break;

                case "Hen":
                    double wingSizeHen = double.Parse(animal[3]);
                    animals = new Hen(name, weight, wingSizeHen);
                    break;

                case "Owl":
                    double wingSizeOwl = double.Parse(animal[3]);
                    animals = new Owl(name, weight, wingSizeOwl);
                    break;

                default:
                    break;
                }
                Console.WriteLine(animals.Sound());
                animalsCollect.Add(animals);

                Food food = null;
                try
                {
                    switch (typeFood)
                    {
                    case "Vegetable":
                        food = new Vegetable(quantity);
                        break;

                    case "Fruit":
                        food = new Fruit(quantity);
                        break;

                    case "Meat":
                        food = new Meat(quantity);
                        break;

                    case "Seeds":
                        food = new Seeds(quantity);
                        break;

                    default:
                        break;
                    }
                    animals.EatFood(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            foreach (var animal in animalsCollect)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            while (true)
            {
                string input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }
                string[] currentAnimal = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string[] currentFood   = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
                try
                {
                    Animal animal       = null;
                    string typeOfAnimal = currentAnimal[0];
                    string animalName   = currentAnimal[1];
                    double animalWeight = double.Parse(currentAnimal[2]);
                    double wingSize;
                    string livingRegion;
                    string breed;
                    switch (typeOfAnimal)
                    {
                    case "Hen":
                        wingSize = double.Parse(currentAnimal[3]);
                        animal   = new Hen(animalName, animalWeight, wingSize);
                        break;

                    case "Owl":
                        wingSize = double.Parse(currentAnimal[3]);
                        animal   = new Owl(animalName, animalWeight, wingSize);
                        break;

                    case "Dog":
                        livingRegion = currentAnimal[3];
                        animal       = new Dog(animalName, animalWeight, livingRegion);
                        break;

                    case "Mouse":
                        livingRegion = currentAnimal[3];
                        animal       = new Mouse(animalName, animalWeight, livingRegion);
                        break;

                    case "Cat":
                        livingRegion = currentAnimal[3];
                        breed        = currentAnimal[4];
                        animal       = new Cat(animalName, animalWeight, livingRegion, breed);
                        break;

                    case "Tiger":
                        livingRegion = currentAnimal[3];
                        breed        = currentAnimal[4];
                        animal       = new Tiger(animalName, animalWeight, livingRegion, breed);
                        break;
                    }
                    animals.Add(animal);

                    Food   food         = null;
                    string typeOfFood   = currentFood[0];
                    int    foodQuantity = int.Parse(currentFood[1]);
                    switch (typeOfFood)
                    {
                    case "Vegetable":
                        food = new Vegetable(foodQuantity);
                        break;

                    case "Seeds":
                        food = new Seeds(foodQuantity);
                        break;

                    case "Fruit":
                        food = new Fruit(foodQuantity);
                        break;

                    case "Meat":
                        food = new Meat(foodQuantity);
                        break;

                    default:
                        break;
                    }

                    Console.WriteLine(animal.ProduceSound());
                    animal.ValidateFood(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (Animal animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            string[] animalInput = Console.ReadLine().Split();
            while (animalInput[0].ToLower() != "end")
            {
                string animalType   = animalInput[0].ToLower();
                string animalName   = animalInput[1];
                double animalWeight = double.Parse(animalInput[2]);

                Animal animal = null;

                if (animalType == "hen")
                {
                    double wingSize = double.Parse(animalInput[3]);

                    animal = new Hen(animalName, animalWeight, wingSize);
                }
                else if (animalType == "owl")
                {
                    double wingSize = double.Parse(animalInput[3]);

                    animal = new Owl(animalName, animalWeight, wingSize);
                }
                else if (animalType == "mouse")
                {
                    string livingRegion = animalInput[3];

                    animal = new Mouse(animalName, animalWeight, livingRegion);
                }
                else if (animalType == "cat")
                {
                    string livingRegion = animalInput[3];
                    string breed        = animalInput[4];

                    animal = new Cat(animalName, animalWeight, livingRegion, breed);
                }
                else if (animalType == "dog")
                {
                    string livingRegion = animalInput[3];

                    animal = new Dog(animalName, animalWeight, livingRegion);
                }
                else if (animalType == "tiger")
                {
                    string livingRegion = animalInput[3];
                    string breed        = animalInput[4];

                    animal = new Tiger(animalName, animalWeight, livingRegion, breed);
                }
                Console.WriteLine(animal.ProduceSound());

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

                string foodType     = foodInput[0].ToLower();
                int    foodQuantity = int.Parse(foodInput[1]);

                Food food = null;

                if (foodType == "vegetable")
                {
                    food = new Vegetable(foodQuantity);
                }
                else if (foodType == "fruit")
                {
                    food = new Fruit(foodQuantity);
                }
                else if (foodType == "meat")
                {
                    food = new Meat(foodQuantity);
                }
                else if (foodType == "seeds")
                {
                    food = new Seeds(foodQuantity);
                }

                animals.Add(animal);

                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }

                animalInput = Console.ReadLine().Split();
            }
            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }