Esempio n. 1
0
        public void ShowAnimalInfo_NewZebraEats_ReturnsAnimalInfo()
        {
            //arrange
            const string expected = "zebra [Bob, 82, Africa, 5]";
            var          test     = new Zebra("Bob", "zebra", 82, "Africa");
            var          testFood = new Vegetable("vegetables", 5);

            test.Eat(testFood);
            //act
            var actual = test.ShowAnimalInfo();

            //assert
            Assert.Equal(expected, actual);
        }
Esempio n. 2
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;
            }
        }
    }
Esempio n. 3
0
        static void Main(string[] args)
        {
            string inputLine;

            while ((inputLine = Console.ReadLine()) != "End")
            {
                string[] animalData = inputLine.Split(new char[] { }, StringSplitOptions.RemoveEmptyEntries);
                string[] foodData   = Console.ReadLine().Split(new char[] { }, StringSplitOptions.RemoveEmptyEntries);

                string animalType   = animalData[0];
                string animalName   = animalData[1];
                double animalWeight = double.Parse(animalData[2]);
                string region       = animalData[3];
                string catBreed     = string.Empty;

                string foodType = foodData[0];
                int    quantity = int.Parse(foodData[1]);


                if (animalData.Length > 4)
                {
                    catBreed = animalData[4];
                }

                if (animalType == "Cat")
                {
                    Animal animal = new Cat(animalType, animalName, animalWeight, region, catBreed);
                    animal.MakeSount();
                    try
                    {
                        Food food = MakeFood(foodType, quantity);
                        animal.Eat(food);
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                    Console.WriteLine(animal);
                }
                else if (animalType == "Mouse")
                {
                    Animal animal = new Mouse(animalType, animalName, animalWeight, region);
                    animal.MakeSount();
                    try
                    {
                        Food food = MakeFood(foodType, quantity);
                        animal.Eat(food);
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                    Console.WriteLine(animal);
                }
                else if (animalType == "Tiger")
                {
                    Animal animal = new Tiger(animalType, animalName, animalWeight, region);
                    animal.MakeSount();
                    try
                    {
                        Food food = MakeFood(foodType, quantity);
                        animal.Eat(food);
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                    Console.WriteLine(animal);
                }
                else if (animalType == "Zebra")
                {
                    Animal animal = new Zebra(animalType, animalName, animalWeight, region);
                    animal.MakeSount();
                    try
                    {
                        Food food = MakeFood(foodType, quantity);
                        animal.Eat(food);
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                    Console.WriteLine(animal);
                }
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var data = "";

            while ((data = Console.ReadLine()) != "End")
            {
                var foodData = Console.ReadLine().Split();
                var array    = data.Split();


                if (array[0] == "Cat")
                {
                    var cat = new Cat(array[1], "Cat", array[3], double.Parse(array[2]), array[4]);
                    if (foodData[0] == "Vegetable")
                    {
                        var vegetable = new Vegetable(int.Parse(foodData[1]));
                        cat.makeSound();
                        cat.Eat(vegetable);
                        Console.WriteLine(cat);
                    }
                    else
                    {
                        var meat = new Meat(int.Parse(foodData[1]));
                        cat.makeSound();
                        cat.Eat(meat);
                        Console.WriteLine(cat);
                    }
                }
                else if (array[0] == "Tiger")
                {
                    var tiger = new Tiger(array[1], "Tiger", array[3], double.Parse(array[2]));
                    if (foodData[0] == "Vegetable")
                    {
                        var vegetable = new Vegetable(int.Parse(foodData[1]));
                        tiger.makeSound();
                        tiger.Eat(vegetable);
                        Console.WriteLine(tiger);
                    }
                    else
                    {
                        var meat = new Meat(int.Parse(foodData[1]));
                        tiger.makeSound();
                        tiger.Eat(meat);
                        Console.WriteLine(tiger);
                    }
                }
                else if (array[0] == "Zebra")
                {
                    var zebra = new Zebra(array[1], "Zebra", array[3], double.Parse(array[2]));
                    if (foodData[0] == "Vegetable")
                    {
                        var vegetable = new Vegetable(int.Parse(foodData[1]));
                        zebra.makeSound();
                        zebra.Eat(vegetable);
                        Console.WriteLine(zebra);
                    }
                    else
                    {
                        var meat = new Meat(int.Parse(foodData[1]));
                        zebra.makeSound();
                        zebra.Eat(meat);
                        Console.WriteLine(zebra);
                    }
                }
                else if (array[0] == "Mouse")
                {
                    var mouse = new Mouse(array[1], "Mouse", array[3], double.Parse(array[2]));
                    if (foodData[0] == "Vegetable")
                    {
                        var vegetable = new Vegetable(int.Parse(foodData[1]));
                        mouse.makeSound();
                        mouse.Eat(vegetable);
                        Console.WriteLine(mouse);
                    }
                    else
                    {
                        var meat = new Meat(int.Parse(foodData[1]));
                        mouse.makeSound();
                        mouse.Eat(meat);
                        Console.WriteLine(mouse);
                    }
                }
            }
        }
Esempio n. 5
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;
                }
            }
        }