Exemplo n.º 1
0
    static void Main()
    {
        string[] input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        while (input[0] != "End")
        {
            string typeOfEnimal = input[0];//Cat,Zebra.....
            string animalName   = input[1];
            double weight       = Convert.ToDouble(input[2]);
            string livingRegion = input[3];

            string[] inputLineTwo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

            string  typeOfFood   = inputLineTwo[0];
            int     quantityFood = int.Parse(inputLineTwo[1]);
            dynamic food         = null;
            switch (typeOfFood)
            {
            case "Vegetable":
                food = new Vegetable(quantityFood, typeOfFood);
                break;

            case "Meat":
                food = new Meat(quantityFood, typeOfFood);
                break;
            }

            switch (typeOfEnimal)
            {
            case "Cat":
                string animalBreed = input[4];
                Animal cat         = new Cat(animalName, typeOfEnimal, weight, food, livingRegion, animalBreed);
                cat.MakeSound();
                Console.WriteLine(cat.ToString());
                break;

            case "Tiger":

                Animal tiger = new Tiger(animalName, typeOfEnimal, weight, food, livingRegion);
                tiger.MakeSound();
                Console.WriteLine(tiger.TooString());
                break;

            case "Zebra":

                Mammal zebra = new Zebra(animalName, typeOfEnimal, weight, food, livingRegion);
                zebra.MakeSound();
                Console.WriteLine(zebra.TooString());


                break;

            case "Mouse":
                Mammal mouse = new Mouse(animalName, typeOfEnimal, weight, food, livingRegion);
                mouse.MakeSound();
                Console.WriteLine(mouse.TooString());
                break;
            }
            input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
    }
Exemplo n.º 2
0
        public void MakeSound_NewZebra_ReturnsZebraSound()
        {
            //arrange
            const string expected = "zzz";
            var          test     = new Zebra("Bob", "zebra", 82, "Africa");
            //act
            var actual = test.MakeSound();

            //assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 3
0
    public static void Main(string[] args)
    {
        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            var animalFoodInfo     = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var animalFoodType     = animalFoodInfo[0];
            var animalFoodQuantity = int.Parse(animalFoodInfo[1]);

            Food food = null;
            switch (animalFoodType)
            {
            case "Vegetable":
                food = new Vegetable(animalFoodQuantity);
                break;

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

            default:
                break;
            }

            var animalInfo         = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var animalType         = animalInfo[0];
            var animalName         = animalInfo[1];
            var animalWeight       = double.Parse(animalInfo[2]);
            var animalLivingRegion = animalInfo[3];

            switch (animalType)
            {
            case "Cat":
                var    animalBreed = animalInfo[4];
                Animal cat         = new Cat(animalType, animalName, animalWeight, animalLivingRegion, animalBreed);
                cat.MakeSound();
                cat.Eat(food);
                Console.WriteLine(cat.ToString());
                break;

            case "Tiger":
                Animal tiger = new Tiger(animalType, animalName, animalWeight, animalLivingRegion);
                tiger.MakeSound();
                tiger.Eat(food);
                Console.WriteLine(tiger.ToString());
                break;

            case "Mouse":
                Animal mouse = new Mouse(animalType, animalName, animalWeight, animalLivingRegion);
                mouse.MakeSound();
                mouse.Eat(food);
                Console.WriteLine(mouse.ToString());
                break;

            case "Zebra":
                Animal zebra = new Zebra(animalType, animalName, animalWeight, animalLivingRegion);
                zebra.MakeSound();
                zebra.Eat(food);
                Console.WriteLine(zebra.ToString());
                break;

            default:
                break;
            }
        }
    }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            string inputLine;

            while (!(inputLine = Console.ReadLine()).Equals("End"))
            {
                var tokensAnimal = inputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var tokensFood   = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                Food food         = null;
                var  nameFood     = tokensFood[0];
                var  foodQuantity = int.Parse(tokensFood[1]);
                switch (tokensFood[0])
                {
                case "Vegetable":
                    food = new Vegetable(foodQuantity);
                    break;

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


                Animal animal;

                var animalName   = tokensAnimal[1];
                var weight       = double.Parse(tokensAnimal[2]);
                var livingRegion = tokensAnimal[3];

                switch (tokensAnimal[0])
                {
                case "Mouse":
                    animal = new Mouse(animalName, weight, livingRegion);
                    animal.MakeSound();
                    animal.Eat(food);
                    Console.WriteLine(animal);
                    break;

                case "Zebra":
                    animal = new Zebra(animalName, weight, livingRegion);
                    animal.MakeSound();
                    animal.Eat(food);
                    Console.WriteLine(animal);
                    break;

                case "Cat":
                    var bread = tokensAnimal[4];
                    animal = new Cat(animalName, weight, livingRegion, bread);
                    animal.MakeSound();
                    animal.Eat(food);
                    Console.WriteLine(animal);
                    break;

                case "Tiger":
                    animal = new Tiger(animalName, weight, livingRegion);
                    animal.MakeSound();
                    animal.Eat(food);
                    Console.WriteLine(animal);
                    break;
                }
            }
        }