/***************************************************************************************************************** * 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(); }
/************************************************************************************************************ * Exercise 1 : Apply OOP concepts (abstraction and encapsulation) to the classes * modify the code to get the output below * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm ***************************************************************************************************************/ private static void Excercise1(EmydexFarmSystem farm) { /* * Animals are loaded only once. For the next time animals are already in the farm. Just need to use them for activities */ Console.WriteLine("Exercise 1 : Press any key when it is time to open the Farm to animals"); Console.ReadKey(); Cow cow = new Cow(); cow.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; farm.Enter(cow); Hen hen = new Hen(); hen.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; farm.Enter(hen); Horse horse = new Horse(); horse.Id = Guid.NewGuid().ToString(); horse.NoOfLegs = 4; farm.Enter(horse); Sheep sheep = new Sheep(); sheep.Id = Guid.NewGuid().ToString(); sheep.NoOfLegs = 4; farm.Enter(sheep); Console.WriteLine(); Console.ReadKey(); }
/***************************************************************************************************************** * 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(); cow.NoOfLegs = 4; farm.Enter(cow); Hen hen = new Hen(); hen.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; farm.Enter(hen); Horse horse = new Horse(); horse.Id = Guid.NewGuid().ToString(); horse.NoOfLegs = 4; farm.Enter(horse); Sheep sheep = new Sheep(); sheep.Id = Guid.NewGuid().ToString(); sheep.NoOfLegs = 4; farm.Enter(sheep); farm.MilkAnimals(); Console.ReadKey(); }
/************************************************************************************************************ * Exercise 1 : Apply OOP concepts (abstraction and encapsulation) to the classes * modify the code to get the output below * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm ***************************************************************************************************************/ private static void Exercise1() { Console.WriteLine("Exercise 1 : Press any key when it is time to open the Farm to animals"); Console.ReadKey(); var farm = new EmydexFarmSystem(); Cow cow = new Cow(); cow.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; farm.Enter(cow); Hen hen = new Hen(); hen.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; farm.Enter(hen); Horse horse = new Horse(); horse.Id = Guid.NewGuid().ToString(); horse.NoOfLegs = 4; farm.Enter(horse); Sheep sheep = new Sheep(); sheep.Id = Guid.NewGuid().ToString(); sheep.NoOfLegs = 4; farm.Enter(sheep); Console.ReadKey(); }
/**************************************************************************************************** * Test Excercise 4 * Modify the EmydexFarmSystem.ReleaseAllAnimals() so that all animals are released (simply clear the collection ) * Expose an event on the FarmSystem FarmEmpty which is invoked once all the animals are released * Subscribe to that event in the main to get the expected output * * Expected Test 4 Program Output * * Exercise 4: Press any key to free all animals * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow has left the farm * Hen has left the farm * Horse has left the farm * Sheep has left the farm * Emydex Farm is now empty ********************************************************************************************************************/ private static void Excercise4() { Console.WriteLine("Exercise 4: Press any key to free all 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.ReleaseAllAnimals(); Console.ReadKey(); }
/*************************************************************************************************************** * Test Excercise 2 * If you have completed the first test excercise, you can continue with the second one * Modify the program and EmydexFarmSystem.MakeNoise() method to get the below output * Expected Test 2 Program Output * * Exercise 2 : Press any key to scare the animals in the farm * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow says Moo! * Hen says CLUCKAAAAAWWWWK! * Horse says Neigh! * Sheep says baa! *****************************************************************************************************************/ private static void Excercise2() { //TODO : Apply OOP concepts and modify the code below to get the required output Console.WriteLine("Exercise 2 : Press any key to scare the animals in the farm"); 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.MakeNoise(); Console.ReadKey(); }
/*************************************************************************************************************** * Test Excercise 2 * If you have completed the first test excercise, you can continue with the second one * Modify the program and EmydexFarmSystem.MakeNoise() method to get the below output * Expected Test 2 Program Output * * Exercise 2 : Press any key to scare the animals in the farm * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow says Moo! * Hen says CLUCKAAAAAWWWWK! * Horse says Neigh! * Sheep says baa! *****************************************************************************************************************/ private static void Excercise2() { //TODO : Apply OOP concepts and modify the code below to get the required output Console.WriteLine("Exercise 2 : Press any key to scare the animals in the farm"); 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.MakeNoise(); }
/**************************************************************************************************** * Test Excercise 4 * Modify the EmydexFarmSystem.ReleaseAllAnimals() so that all animals are released (simply clear the collection ) * Expose an event on the FarmSystem FarmEmpty which is invoked once all the animals are released * Subscribe to that event in the main to get the expected output * * Expected Test 4 Program Output * * Exercise 4: Press any key to free all animals * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow has left the farm * Hen has left the farm * Horse has left the farm * Sheep has left the farm * Emydex Farm is now empty ********************************************************************************************************************/ private static void Excercise4() { //TODO : Apply OOP concepts and modify the code below to get the required output Console.WriteLine("Exercise 4: Press any key to free all animals"); Console.ReadKey(); var farm = new EmydexFarmSystem(); Cow cow = new Cow(); cow.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; cow.Name = "Cow"; farm.Enter(cow); Hen hen = new Hen(); hen.Id = Guid.NewGuid().ToString(); hen.NoOfLegs = 4; hen.Name = "Hen"; farm.Enter(hen); Horse horse = new Horse(); horse.Id = Guid.NewGuid().ToString(); horse.NoOfLegs = 4; horse.Name = "Horse"; farm.Enter(horse); Sheep sheep = new Sheep(); sheep.Id = Guid.NewGuid().ToString(); sheep.NoOfLegs = 4; sheep.Name = "Sheep"; farm.Enter(sheep); Animal animal1 = new Animal { Id = cow.Id }; Animal animal2 = new Animal { Id = hen.Id }; Animal animal3 = new Animal { Id = horse.Id }; Animal animal4 = new Animal { Id = sheep.Id }; List <Animal> listOfAnimals = new List <Animal>(); listOfAnimals.Add(animal1); listOfAnimals.Add(animal2); listOfAnimals.Add(animal3); listOfAnimals.Add(animal4); farm.ReleaseAllAnimals(listOfAnimals); }
/**************************************************************************************************** * Test Excercise 4 * Modify the EmydexFarmSystem.ReleaseAllAnimals() so that all animals are released (simply clear the collection ) * Expose an event on the FarmSystem FarmEmpty which is invoked once all the animals are released * Subscribe to that event in the main to get the expected output * * Expected Test 4 Program Output * * Exercise 4: Press any key to free all animals * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow has left the farm * Hen has left the farm * Horse has left the farm * Sheep has left the farm * Emydex Farm is now empty ********************************************************************************************************************/ private static void Excercise4() { //TODO : Apply OOP concepts and modify the code below to get the required output Console.WriteLine("Exercise 4: Press any key to free all animals"); Console.ReadKey(); using (EmydexFarmSystem farm = new EmydexFarmSystem()) { // Subscribe to the farmempty event farm.FarmEmpty += (s, e) => { Console.WriteLine("Emydex Farm is now empty"); }; //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.ReleaseAllAnimals(); } Console.ReadKey(); }
/// <summary> /// Animals enter into farm /// </summary> /// <param name="farm">Farm</param> private static void AnimalsInFarm(EmydexFarmSystem farm) { Animal cow = new Cow(Guid.NewGuid().ToString(), 4); farm.Enter(cow); Animal hen = new Hen(Guid.NewGuid().ToString(), 4); farm.Enter(hen); Animal horse = new Horse(Guid.NewGuid().ToString(), 4); farm.Enter(horse); Animal sheep = new Sheep(Guid.NewGuid().ToString(), 4); farm.Enter(sheep); }
/**************************************************************************************************** * Test Excercise 4 * Modify the EmydexFarmSystem.ReleaseAllAnimals() so that all animals are released (simply clear the collection ) * Expose an event on the FarmSystem FarmEmpty which is invoked once all the animals are released * Subscribe to that event in the main to get the expected output * * Expected Test 4 Program Output * * Exercise 4: Press any key to free all animals * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow has left the farm * Hen has left the farm * Horse has left the farm * Sheep has left the farm * Emydex Farm is now empty ********************************************************************************************************************/ private static void Excercise4() { // Local function to write out when the farm is empty void FarmEmptied() { Console.WriteLine("Emydex Farm is now empty"); } //TODO : Apply OOP concepts and modify the code below to get the required output Console.WriteLine("Exercise 4: Press any key to free all animals"); Console.ReadKey(); var farm = new EmydexFarmSystem(); // Subscribe To when the Farm is emptied farm.FarmEmpty += FarmEmptied; Cow cow = new Cow(); cow.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; farm.Enter(cow); Hen hen = new Hen(); hen.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; farm.Enter(hen); Horse horse = new Horse(); horse.Id = Guid.NewGuid().ToString(); horse.NoOfLegs = 4; farm.Enter(horse); Sheep sheep = new Sheep(); sheep.Id = Guid.NewGuid().ToString(); sheep.NoOfLegs = 4; farm.Enter(sheep); farm.ReleaseAllAnimals(); Console.ReadKey(); }
/**************************************************************************************************** * Test Excercise 4 * Modify the EmydexFarmSystem.ReleaseAllAnimals() so that all animals are released (simply clear the collection ) * Expose an event on the FarmSystem FarmEmpty which is invoked once all the animals are released * Subscribe to that event in the main to get the expected output * * Expected Test 4 Program Output * * Exercise 4: Press any key to free all animals * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow has left the farm * Hen has left the farm * Horse has left the farm * Sheep has left the farm * Emydex Farm is now empty ********************************************************************************************************************/ private static void Excercise4() { //TODO : Apply OOP concepts and modify the code below to get the required output Console.WriteLine("Exercise 4: Press any key to free all animals"); Console.ReadKey(); var farm = new EmydexFarmSystem(); var cow = new Cow { Id = Guid.NewGuid().ToString(), NoOfLegs = 4 }; farm.Enter(cow); var hen = new Hen { Id = Guid.NewGuid().ToString(), NoOfLegs = 2 }; farm.Enter(hen); var horse = new Horse { Id = Guid.NewGuid().ToString(), NoOfLegs = 4 }; farm.Enter(horse); var sheep = new Sheep { Id = Guid.NewGuid().ToString(), NoOfLegs = 4 }; farm.Enter(sheep); farm.ReleaseAllAnimals(); Console.ReadKey(); }
/************************************************************************************************************ * Exercise 1 : Apply OOP concepts (abstraction and encapsulation) to the classes * modify the code to get the output below * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm ***************************************************************************************************************/ private static void Excercise1() { Console.WriteLine("Exercise 1 : Press any key when it is time to open the Farm to animals"); Console.ReadKey(); var farm = new EmydexFarmSystem(); var cow = new Cow { Id = Guid.NewGuid().ToString(), NoOfLegs = 4 }; farm.Enter(cow); var hen = new Hen { Id = Guid.NewGuid().ToString(), NoOfLegs = 2 }; farm.Enter(hen); var horse = new Horse { Id = Guid.NewGuid().ToString(), NoOfLegs = 4 }; farm.Enter(horse); var sheep = new Sheep { Id = Guid.NewGuid().ToString(), NoOfLegs = 4 }; farm.Enter(sheep); Console.ReadKey(); }
/************************************************************************************************************ * Exercise 1 : Apply OOP concepts (abstraction and encapsulation) to the classes * modify the code to get the output below * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm ***************************************************************************************************************/ private static void Excercise1() { Console.WriteLine("Exercise 1 : Press any key when it is time to open the Farm to 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); Console.ReadKey(); }
/**************************************************************************************************** * Test Exercise 4 * Modify the EmydexFarmSystem.ReleaseAllAnimals() so that all animals are released (simply clear the collection ) * Expose an event on the FarmSystem FarmEmpty which is invoked once all the animals are released * Subscribe to that event in the main to get the expected output * * Expected Test 4 Program Output * * Exercise 4: Press any key to free all animals * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow has left the farm * Hen has left the farm * Horse has left the farm * Sheep has left the farm * Emydex Farm is now empty ********************************************************************************************************************/ private static void Exercise4() { //TODO : Apply OOP concepts and modify the code below to get the required output Console.WriteLine("Exercise 4: Press any key to free all animals"); Console.ReadKey(); var farm = new EmydexFarmSystem(); farm.FarmEmpty += new EmydexFarmSystem.eventRaiser(farm.farmEmpty); Cow cow = new Cow(); cow.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; farm.Enter(cow); Hen hen = new Hen(); hen.Id = Guid.NewGuid().ToString(); cow.NoOfLegs = 4; farm.Enter(hen); Horse horse = new Horse(); horse.Id = Guid.NewGuid().ToString(); horse.NoOfLegs = 4; farm.Enter(horse); Sheep sheep = new Sheep(); sheep.Id = Guid.NewGuid().ToString(); sheep.NoOfLegs = 4; farm.Enter(sheep); farm.ReleaseAllAnimals(); Console.ReadKey(); }
/************************************************************************************************************ * Exercise 1 : Apply OOP concepts (abstraction and encapsulation) to the classes * modify the code to get the output below * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm ***************************************************************************************************************/ private static void Excercise1() { Console.WriteLine("Exercise 1 : Press any key when it is time to open the Farm to animals"); Console.ReadKey(); var farm = new EmydexFarmSystem(); var allAnimals = new List <IAnimal>() { { new Cow() }, { new Hen() }, { new Horse() }, { new Sheep() } }; farm.Enter(allAnimals); Console.ReadKey(); }
/*************************************************************************************************************** * Test Excercise 2 * If you have completed the first test excercise, you can continue with the second one * Modify the program and EmydexFarmSystem.MakeNoise() method to get the below output * Expected Test 2 Program Output * * Exercise 2 : Press any key to scare the animals in the farm * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow says Moo! * Hen says CLUCKAAAAAWWWWK! * Horse says Neigh! * Sheep says baa! *****************************************************************************************************************/ private static void Excercise2() { //TODO : Apply OOP concepts and modify the code below to get the required output Console.WriteLine("Exercise 2 : Press any key to scare the animals in the farm"); 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.MakeNoise(); } Console.ReadKey(); }
/*************************************************************************************************************** * Test Excercise 2 * If you have completed the first test excercise, you can continue with the second one * Modify the program and EmydexFarmSystem.MakeNoise() method to get the below output * Expected Test 2 Program Output * * Exercise 2 : Press any key to scare the animals in the farm * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm * Cow says Moo! * Hen says CLUCKAAAAAWWWWK! * Horse says Neigh! * Sheep says baa! *****************************************************************************************************************/ private static void Excercise2() { Console.WriteLine("Exercise 2 : Press any key to scare the animals in the farm"); Console.ReadKey(); var farm = new EmydexFarmSystem(); var allAnimals = new List <IAnimal>() { { new Cow() }, { new Hen() }, { new Horse() }, { new Sheep() } }; farm.Enter(allAnimals); farm.MakeNoise(); Console.ReadKey(); }
/************************************************************************************************************ * Exercise 1 : Apply OOP concepts (abstraction and encapsulation) to the classes * modify the code to get the output below * Cow has entered the farm * Hen has entered the farm * Horse has entered the farm * Sheep has entered the farm ***************************************************************************************************************/ private static void Excercise1() { Console.WriteLine("Exercise 1 : Press any key when it is time to open the Farm to animals"); Console.ReadKey(); // initial the farm class using (EmydexFarmSystem farm = new EmydexFarmSystem()) { // List of animals in order, can be initiated only once at the begining of the program, instead of each exercise // List<IAnimal> animals = new List<IAnimal>() { new Cow(), new Hen(), new Horse(), new Sheep() }; // loop through animals to enter the farm one after the other 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); }); } Console.ReadKey(); }