コード例 #1
0
/*****************************************************************************************************************
 * Test Excercise 3
 * If you have completed the previous test excercise, you can continue with this one
 * The project includes an interface IMilkableAnimal. Make use of this interface to implement on the relevant classes
 * so that calling the EmydexFarmSystem.MilkAnimals() method to get the below output
 *
 * Expected Test 3 Program Output
 *
 * Exercise 3 : Press any key when it is time to milk animals
 * Cow has entered the farm
 * Hen has entered the farm
 * Horse has entered the farm
 * Sheep has entered the farm
 * Cow was milked!
 ************************************************************************************************************/
        private static void Excercise3()
        {
            //TODO : Apply OOP concepts and modify the code below to get the required output
            Console.WriteLine("Exercise 3 : Press any key when it is time to milk animals");
            Console.ReadKey();
            var farm = new EmydexFarmSystem();
            Cow cow  = new Cow();

            cow.Id = Guid.NewGuid().ToString();
            farm.Enter(cow);

            Hen hen = new Hen();

            hen.Id       = Guid.NewGuid().ToString();
            hen.NoOfLegs = 2;
            farm.Enter(hen);

            Horse horse = new Horse();

            horse.Id = Guid.NewGuid().ToString();
            farm.Enter(horse);

            Sheep sheep = new Sheep();

            sheep.Id = Guid.NewGuid().ToString();
            farm.Enter(sheep);

            farm.MilkAnimals(cow);
        }
コード例 #2
0
/*****************************************************************************************************************
 * Test Excercise 3
 * If you have completed the previous test excercise, you can continue with this one
 * The project includes an interface IMilkableAnimal. Make use of this interface to implement on the relevant classes
 * so that calling the EmydexFarmSystem.MilkAnimals() method to get the below output
 *
 * Expected Test 3 Program Output
 *
 * Exercise 3 : Press any key when it is time to milk animals
 * Cow has entered the farm
 * Hen has entered the farm
 * Horse has entered the farm
 * Sheep has entered the farm
 * Cow was milked!
 ************************************************************************************************************/
        private static void Excercise3()
        {
            Console.WriteLine("Exercise 3 : Press any key when it is time to milk animals");
            Console.ReadKey();

            var farm = new EmydexFarmSystem();

            Cow cow = new Cow();

            farm.Enter(cow);

            Hen hen = new Hen();

            farm.Enter(hen);

            Horse horse = new Horse();

            farm.Enter(horse);

            Sheep sheep = new Sheep();

            farm.Enter(sheep);

            farm.MilkAnimals();

            Console.ReadKey();
        }
コード例 #3
0
/*****************************************************************************************************************
 * Test Excercise 3
 * If you have completed the previous test excercise, you can continue with this one
 * The project includes an interface IMilkableAnimal. Make use of this interface to implement on the relevant classes
 * so that calling the EmydexFarmSystem.MilkAnimals() method to get the below output
 *
 * Expected Test 3 Program Output
 *
 * Exercise 3 : Press any key when it is time to milk animals
 * Cow has entered the farm
 * Hen has entered the farm
 * Horse has entered the farm
 * Sheep has entered the farm
 * Cow was milked!
 ************************************************************************************************************/
        private static void Excercise3()
        {
            //TODO : Apply OOP concepts and modify the code below to get the required output
            Console.WriteLine("Exercise 3 : Press any key when it is time to milk animals");
            Console.ReadKey();
            var farm = new EmydexFarmSystem();
            Cow cow  = new Cow();

            farm.Enter(cow); // can pass constructor too, ex. farm.Enter(new Cow());

            Hen hen = new Hen();

            farm.Enter(hen);

            Horse horse = new Horse();

            farm.Enter(horse);

            Sheep sheep = new Sheep();

            farm.Enter(sheep);

            farm.MilkAnimals();
            Console.ReadKey();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Luke-Wu/FarmSystem
/*****************************************************************************************************************
 * Test Excercise 3
 * If you have completed the previous test excercise, you can continue with this one
 * The project includes an interface IMilkableAnimal. Make use of this interface to implement on the relevant classes
 * so that calling the EmydexFarmSystem.MilkAnimals() method to get the below output
 *
 * Expected Test 3 Program Output
 *
 * Exercise 3 : Press any key when it is time to milk animals
 * Cow has entered the farm
 * Hen has entered the farm
 * Horse has entered the farm
 * Sheep has entered the farm
 * Cow was milked!
 ************************************************************************************************************/
        private static void Excercise3()
        {
            //TODO : Apply OOP concepts and modify the code below to get the required output
            Console.WriteLine("Exercise 3 : Press any key when it is time to milk animals");
            Console.ReadKey();
            var farm = new EmydexFarmSystem();

            AnimalsInFarm(farm);

            farm.MilkAnimals();
            Console.ReadKey();
        }
コード例 #5
0
        /*****************************************************************************************************************
         * Test Exercise 3
         * If you have completed the previous test exercise, you can continue with this one
         * The project includes an interface IMilkableAnimal. Make use of this interface to implement on the relevant classes
         * so that calling the EmydexFarmSystem.MilkAnimals() method to get the below output
         *
         * Expected Test 3 Program Output
         *
         * Exercise 3 : Press any key when it is time to milk animals
         * Cow has entered the farm
         * Hen has entered the farm
         * Horse has entered the farm
         * Sheep has entered the farm
         * Cow was milked!
         ************************************************************************************************************/
        private static void Exercise3()
        {
            Console.WriteLine("Exercise 3 : Press any key when it is time to milk animals");
            Console.ReadKey(true);

            var farm = new EmydexFarmSystem();

            farm.EnterMob
            (
                CreateMob()
            );
            farm.MilkAnimals();

            Console.WriteLine();
            Console.ReadKey(true);
        }
コード例 #6
0
        /*****************************************************************************************************************
         * Test Excercise 3
         * If you have completed the previous test excercise, you can continue with this one
         * The project includes an interface IMilkableAnimal. Make use of this interface to implement on the relevant classes
         * so that calling the EmydexFarmSystem.MilkAnimals() method to get the below output
         *
         * Expected Test 3 Program Output
         *
         * Exercise 3 : Press any key when it is time to milk animals
         * Cow has entered the farm
         * Hen has entered the farm
         * Horse has entered the farm
         * Sheep has entered the farm
         * Cow was milked!
         ************************************************************************************************************/
        private static void Excercise3()
        {
            //TODO : Apply OOP concepts and modify the code below to get the required output
            Console.WriteLine("Exercise 3 : Press any key when it is time to milk animals");
            Console.ReadKey();

            using (EmydexFarmSystem farm = new EmydexFarmSystem())
            {
                //List<IAnimal> animals = new List<IAnimal>() { new Cow(), new Hen(), new Horse(), new Sheep() };
                animals.ForEach(animal =>
                {
                    // Assign an Id to each animal,
                    // the NoOfLegs can be predefined within the class as they do not change, but still can be changed setting the property
                    animal.Id = Guid.NewGuid().ToString();
                    // Enter the farm
                    farm.Enter(animal);
                });
                farm.MilkAnimals();
            }
            Console.ReadKey();
        }