Ejemplo n.º 1
0
        public void TigerEats()
        {
            Tiger  tiger = new Tiger();
            string meat  = tiger.Eat();

            Assert.Equal("I eat my meat rare", meat);
        }
Ejemplo n.º 2
0
        private List <IAnimal> OperateTiger(string[] input, List <IAnimal> animals)
        {
            string name   = input[1];
            double weight = double.Parse(input[2]);
            Animal animal = new Tiger(name, weight, input[3], input[4]);

            string[] inputFood = Console.ReadLine().Split();
            Food     food      = CreateFood(inputFood);

            Console.WriteLine(animal.ProduceSound());
            animal.Eat(food);
            animals.Add(animal);
            return(animals);
        }
Ejemplo n.º 3
0
        public void ShowAnimalInfo_NewTigerEats_ReturnsAnimalInfo()
        {
            //arrange
            const string expected = "tiger [Bob, 82, Africa, 2]";
            var          test     = new Tiger("Bob", "tiger", 82, "Africa");
            var          testFood = new Meat("meat", 2);

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

            //assert
            Assert.Equal(expected, actual);
        }
        static void Main2()
        {
            Tiger tiger = new Tiger();

            Console.WriteLine(tiger.Eat());
            Console.WriteLine(tiger.Hunt());

            Animal animal = tiger;

            Console.WriteLine(animal.Eat());


            Tiger tiger2 = (Tiger)animal; //do it at my risk!

            Console.WriteLine(tiger.Hunt());
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            NoasArk noasArk = new NoasArk(numberOfCages: 20);

            Tiger tiger = new Tiger(stripeCount: 10, birthdate: new DateTime(2010, 11, 10), gender: Gender.Female);

            Panda panda = new Panda(birthdate: new DateTime(2016, 1, 1), gender: Gender.Male);

            Rabbit rabbit = new Rabbit(birthdate: new DateTime(2016, 1, 1), gender: Gender.Male);

            noasArk.Load(tiger);

            noasArk.Load(panda);

            noasArk.Load(rabbit);

            noasArk.RollCall();

            tiger.Eat();

            rabbit.Eat();
        }
Ejemplo n.º 6
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;
            }
        }
    }
Ejemplo n.º 7
0
    static void Main(string[] args)
    {
        List <Animal> farm  = new List <Animal>();
        List <Food>   foods = new List <Food>();
        string        input;

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

            string animalType   = animalArgs[0];
            string animalName   = animalArgs[1];
            double animalWeight = double.Parse(animalArgs[2]);
            Animal animal       = null;

            string foodType     = foodArgs[0];
            int    foodQuantity = int.Parse(foodArgs[1]);
            Food   food         = null;

            switch (animalType)
            {
            case "Hen":
                double henWingSize = double.Parse(animalArgs[3]);
                animal = new Hen(animalName, animalWeight, henWingSize);
                break;

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

            case "Mouse":
                string mouseLivingRegion = animalArgs[3];
                animal = new Mouse(animalName, animalWeight, mouseLivingRegion);
                break;

            case "Cat":
                string catLivingRegion = animalArgs[3];
                string catBreed        = animalArgs[4];
                animal = new Cat(animalName, animalWeight, catLivingRegion, catBreed);
                break;

            case "Dog":
                string dogLivingRegion = animalArgs[3];
                animal = new Dog(animalName, animalWeight, dogLivingRegion);
                break;

            case "Tiger":
                string tigerLivingRegion = animalArgs[3];
                string tigerBreed        = animalArgs[4];
                animal = new Tiger(animalName, animalWeight, tigerLivingRegion, tigerBreed);
                break;
            }

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

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

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

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

            farm.Add(animal);
            foods.Add(food);
        }

        int foodIndex = 0;

        foreach (var animal in farm)
        {
            try
            {
                animal.AskForFood();
                animal.Eat(foods[foodIndex++]);
            }
            catch (WrongFoodException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        farm.ForEach(a => Console.WriteLine(a));
    }
    public static void Main()
    {
        string        input   = string.Empty;
        List <Animal> animals = new List <Animal>();

        while ((input = Console.ReadLine()) != "End")
        {
            List <string> animalParams = input.Split().ToList();
            Animal        animal       = null;

            switch (animalParams[0].ToLower())
            {
            case "mouse":
                animal = new Mouse(animalParams[1], double.Parse(animalParams[2]), animalParams[3]);
                break;

            case "dog":
                animal = new Dog(animalParams[1], double.Parse(animalParams[2]), animalParams[3]);
                break;

            case "owl":
                animal = new Owl(animalParams[1], double.Parse(animalParams[2]), double.Parse(animalParams[3]));
                break;

            case "hen":
                animal = new Hen(animalParams[1], double.Parse(animalParams[2]), double.Parse(animalParams[3]));
                break;

            case "cat":
                animal = new Cat(animalParams[1], double.Parse(animalParams[2]), animalParams[3], animalParams[4]);
                break;

            case "tiger":
                animal = new Tiger(animalParams[1], double.Parse(animalParams[2]), animalParams[3], animalParams[4]);
                break;

            default:
                break;
            }

            Console.WriteLine(animal.MakeSound());

            animals.Add(animal);

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

            Food food = null;

            switch (foodItems[0])
            {
            case nameof(Fruit):
                food = new Fruit(int.Parse(foodItems[1]));
                break;

            case nameof(Vegetable):
                food = new Vegetable(int.Parse(foodItems[1]));
                break;

            case nameof(Meat):
                food = new Meat(int.Parse(foodItems[1]));
                break;

            case nameof(Seeds):
                food = new Seeds(int.Parse(foodItems[1]));
                break;
            }

            string eatResult = animal.Eat(food);

            if (eatResult != null)
            {
                Console.WriteLine(eatResult);
            }
        }

        foreach (Animal animal in animals)
        {
            Console.WriteLine(animal);
        }
    }
Ejemplo n.º 9
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);
                    }
                }
            }
        }
Ejemplo n.º 10
0
    static void Main(string[] args)
    {
        List <Animal> animals = new List <Animal>();
        string        inputAnimal;

        while ((inputAnimal = Console.ReadLine()) != "End")
        {
            string[] dataAnimal = inputAnimal.Split(' ', StringSplitOptions.RemoveEmptyEntries);
            string[] dataFood   = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

            switch (dataAnimal[0])
            {
            case "Owl":
                Owl owl = new Owl(dataAnimal[1], double.Parse(dataAnimal[2]), double.Parse(dataAnimal[3]));
                Console.WriteLine(owl.AskForFood());
                owl.Eat(dataFood[0], int.Parse(dataFood[1]));
                animals.Add(owl);
                break;

            case "Hen":
                Hen hen = new Hen(dataAnimal[1], double.Parse(dataAnimal[2]), double.Parse(dataAnimal[3]));
                Console.WriteLine(hen.AskForFood());
                hen.Eat(dataFood[0], int.Parse(dataFood[1]));
                animals.Add(hen);
                break;

            case "Mouse":
                Mouse mouse = new Mouse(dataAnimal[1], double.Parse(dataAnimal[2]), dataAnimal[3]);
                Console.WriteLine(mouse.AskForFood());
                mouse.Eat(dataFood[0], int.Parse(dataFood[1]));
                animals.Add(mouse);
                break;

            case "Dog":
                Dog dog = new Dog(dataAnimal[1], double.Parse(dataAnimal[2]), dataAnimal[3]);
                Console.WriteLine(dog.AskForFood());
                dog.Eat(dataFood[0], int.Parse(dataFood[1]));
                animals.Add(dog);
                break;

            case "Cat":
                Cat cat = new Cat(dataAnimal[1], double.Parse(dataAnimal[2]), dataAnimal[3], dataAnimal[4]);
                Console.WriteLine(cat.AskForFood());
                cat.Eat(dataFood[0], int.Parse(dataFood[1]));
                animals.Add(cat);
                break;

            case "Tiger":
                Tiger tiger = new Tiger(dataAnimal[1], double.Parse(dataAnimal[2]), dataAnimal[3], dataAnimal[4]);
                Console.WriteLine(tiger.AskForFood());
                tiger.Eat(dataFood[0], int.Parse(dataFood[1]));
                animals.Add(tiger);
                break;
            }
        }

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

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                string[] animalArgs = command.Split();
                string[] foodArgs   = Console.ReadLine().Split();

                string animal = animalArgs[0];
                string name   = animalArgs[1];
                double weight = double.Parse(animalArgs[2]);

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

                try
                {
                    if (animal == "Hen" || animal == "Owl")
                    {
                        double wingSize = double.Parse(animalArgs[3]);
                        if (animal == "Hen")
                        {
                            Animal hen = new Hen(name, weight, foodType, foodQuantity, wingSize);
                            Console.WriteLine(hen.ToString());

                            animals.Add(hen);

                            hen.Eat();
                        }
                        else
                        {
                            Animal owl = new Owl(name, weight, foodType, foodQuantity, wingSize);
                            Console.WriteLine(owl.ToString());

                            animals.Add(owl);

                            owl.Eat();
                        }
                    }
                    else if (animal == "Tiger" || animal == "Cat")
                    {
                        string livinRedion = animalArgs[3];
                        string bread       = animalArgs[4];
                        if (animal == "Tiger")
                        {
                            Tiger tiger = new Tiger(name, weight, foodType, livinRedion, foodQuantity, bread);
                            Console.WriteLine(tiger.ToString());

                            animals.Add(tiger);

                            tiger.Eat();
                        }
                        else
                        {
                            Cat cat = new Cat(name, weight, foodType, livinRedion, foodQuantity, bread);
                            Console.WriteLine(cat.ToString());

                            animals.Add(cat);

                            cat.Eat();
                        }
                    }
                    else if (animal == "Mouse" || animal == "Dog")
                    {
                        string livingRedion = animalArgs[3];
                        if (animal == "Mouse")
                        {
                            Mouse mouse = new Mouse(name, weight, foodType, livingRedion, foodQuantity);
                            Console.WriteLine(mouse.ToString());

                            animals.Add(mouse);

                            mouse.Eat();
                        }
                        else
                        {
                            Dog dog = new Dog(name, weight, foodType, livingRedion, foodQuantity);
                            Console.WriteLine(dog.ToString());

                            animals.Add(dog);

                            dog.Eat();
                        }
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }

            foreach (Animal animal in animals)
            {
                if (animal is Bird)
                {
                    var bird = (Bird)animal;
                    Console.WriteLine($"{bird.GetType().Name} [{bird.Name}, {bird.WingSize}, {bird.Weight}, {bird.FoodQuantity}]");
                }
                else if (animal is Feline)
                {
                    var feline = (Feline)animal;
                    Console.WriteLine($"{feline.GetType().Name} [{feline.Name}, {feline.Bread}, {feline.Weight}, {feline.LivingRegion}, {feline.FoodQuantity}]");
                }
                else
                {
                    var mimmal = (Mammal)animal;
                    Console.WriteLine($"{mimmal.GetType().Name} [{mimmal.Name}, {mimmal.Weight}, {mimmal.LivingRegion}, {mimmal.FoodQuantity}]");
                }
            }
        }
Ejemplo n.º 12
0
        public void CanTigerEat()
        {
            Tiger tiger = new Tiger();

            Assert.True(tiger.Eat());
        }
Ejemplo n.º 13
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);
                }
            }
        }
Ejemplo n.º 14
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;
                }
            }
        }
Ejemplo n.º 15
0
    public static void Main()
    {
        var animals = new List <Animal>();

        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            var animalInfo = input.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            var foodInfo   = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            var animalType   = animalInfo[0];
            var foodType     = foodInfo[0];
            var foodQuantity = int.Parse(foodInfo[1]);

            if (animalType == "Hen")
            {
                var hen = new Hen(animalInfo[1], double.Parse(animalInfo[2]), double.Parse(animalInfo[3]));
                hen.ProduceSound();
                hen.Eat(foodQuantity);
                animals.Add(hen);
            }
            else if (animalType == "Mouse")
            {
                var mouse = new Mouse(animalInfo[1], double.Parse(animalInfo[2]), animalInfo[3]);
                mouse.ProduceSound();
                if (mouse.FavouriteFood.Contains(foodType))
                {
                    mouse.Eat(foodQuantity);
                }
                else
                {
                    NotFavouriteFood(animalType, foodType);
                }
                animals.Add(mouse);
            }
            else if (animalType == "Cat")
            {
                var cat = new Cat(animalInfo[1], double.Parse(animalInfo[2]), animalInfo[3], animalInfo[4]);
                cat.ProduceSound();

                if (cat.FavouriteFood.Contains(foodType))
                {
                    cat.Eat(foodQuantity);
                }
                else
                {
                    NotFavouriteFood(animalType, foodType);
                }
                animals.Add(cat);
            }
            else if (animalType == "Tiger")
            {
                var tiger = new Tiger(animalInfo[1], double.Parse(animalInfo[2]), animalInfo[3], animalInfo[4]);
                tiger.ProduceSound();
                if (tiger.FavouriteFood.Contains(foodType))
                {
                    tiger.Eat(foodQuantity);
                }
                else
                {
                    NotFavouriteFood(animalType, foodType);
                }
                animals.Add(tiger);
            }
            else if (animalType == "Dog")
            {
                var dog = new Dog(animalInfo[1], double.Parse(animalInfo[2]), animalInfo[3]);
                dog.ProduceSound();
                if (dog.FavouriteFood.Contains(foodType))
                {
                    dog.Eat(foodQuantity);
                }
                else
                {
                    NotFavouriteFood(animalType, foodType);
                }
                animals.Add(dog);
            }
            else if (animalType == "Owl")
            {
                var owl = new Owl(animalInfo[1], double.Parse(animalInfo[2]), double.Parse(animalInfo[3]));
                owl.ProduceSound();
                if (owl.FavouriteFood.Contains(foodType))
                {
                    owl.Eat(foodQuantity);
                }
                else
                {
                    NotFavouriteFood(animalType, foodType);
                }
                animals.Add(owl);
            }
        }

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