Example #1
0
        public static void Main()
        {
            string animalInfo = "";
            string foodInfo   = "";

            while (true)
            {
                animalInfo = Console.ReadLine();
                if (animalInfo == "End")
                {
                    break;
                }
                foodInfo = Console.ReadLine();

                string[] animalArgs         = animalInfo.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   animalType         = animalArgs[0];
                string   animalName         = animalArgs[1];
                double   animalWeight       = double.Parse(animalArgs[2]);
                string   animalLivingRegion = animalArgs[3];
                string   catBreed           = "";
                if (animalArgs.Length == 5)
                {
                    catBreed = animalArgs[4];
                }

                string[] foodArgs = foodInfo.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   foodType = foodArgs[0];
                int      quantiy  = int.Parse(foodArgs[1]);
                Food     currentFood;
                if (foodType == "Vegetable")
                {
                    currentFood = new Vegetable(quantiy);
                }
                else
                {
                    currentFood = new Meat(quantiy);
                }

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

                case "Cat":
                    Animal cat = new Cat(animalType, animalName, animalWeight, animalLivingRegion, catBreed);
                    cat.MakeSound();
                    cat.Eat(currentFood);
                    Console.WriteLine(cat);
                    break;

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

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

                default:
                    break;
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            string[] inputAnimal = Console.ReadLine().Split(new[] { ' ' },
                                                            StringSplitOptions.RemoveEmptyEntries);
            string[] inputFood = Console.ReadLine().Split(new[] { ' ' },
                                                          StringSplitOptions.RemoveEmptyEntries);
            List <Animal> animals = new List <Animal>();

            while (inputAnimal[0] != "End")
            {
                string getTypeAnimal = inputAnimal[0].ToLower();
                string name          = inputAnimal[1];
                double weight        = double.Parse(inputAnimal[2]);
                string livingRegion  = inputAnimal[3];


                string getTypeFood  = inputFood[0].ToLower();
                int    foodQuantity = int.Parse(inputFood[1]);



                switch (getTypeAnimal)
                {
                case "cat":
                    string breed = inputAnimal[4];
                    Cat    cat   = new Cat(name, weight, livingRegion, breed);
                    cat.MakeSound();
                    animals.Add(cat);
                    switch (getTypeFood)
                    {
                    case "vegetable":
                        Vegetable veg = new Vegetable(foodQuantity);
                        cat.Eat(veg);
                        Console.WriteLine(cat);
                        break;

                    case "meat":
                        Meat meat = new Meat(foodQuantity);
                        cat.Eat(meat);
                        Console.WriteLine(cat);
                        break;
                    }
                    break;

                case "tiger":
                    Tiger tiger = new Tiger(name, weight, livingRegion);
                    tiger.MakeSound();
                    animals.Add(tiger);
                    switch (getTypeFood)
                    {
                    case "vegetable":
                        Vegetable veg = new Vegetable(foodQuantity);
                        tiger.Eat(veg);
                        Console.WriteLine(tiger);
                        break;

                    case "meat":
                        Meat meat = new Meat(foodQuantity);
                        tiger.Eat(meat);
                        Console.WriteLine(tiger);
                        break;
                    }
                    break;

                case "mouse":
                    Mouse mouse = new Mouse(name, weight, livingRegion);
                    mouse.MakeSound();
                    switch (getTypeFood)
                    {
                    case "vegetable":
                        Vegetable veg = new Vegetable(foodQuantity);
                        mouse.Eat(veg);
                        Console.WriteLine(mouse);
                        break;

                    case "meat":
                        Meat meat = new Meat(foodQuantity);
                        mouse.Eat(meat);
                        Console.WriteLine(mouse);
                        break;
                    }
                    break;

                case "zebra":
                    Zebra zebra = new Zebra(name, weight, livingRegion);
                    zebra.MakeSound();
                    switch (getTypeFood)
                    {
                    case "vegetable":
                        Vegetable veg = new Vegetable(foodQuantity);
                        zebra.Eat(veg);
                        Console.WriteLine(zebra);
                        break;

                    case "meat":
                        Meat meat = new Meat(foodQuantity);
                        zebra.Eat(meat);
                        Console.WriteLine(zebra);
                        break;
                    }
                    break;
                }
                inputAnimal = Console.ReadLine().Split(new[] { ' ' },
                                                       StringSplitOptions.RemoveEmptyEntries);
                if (inputAnimal[0] == "End")
                {
                    break;
                }
                inputFood = Console.ReadLine().Split(new[] { ' ' },
                                                     StringSplitOptions.RemoveEmptyEntries);
            }

            foreach (var animal in animals)
            {
                //animal.MakeSound();
            }
        }