With as many animals and possible animals that the zoo has/can have, the Animal class will become unwieldy.
This page is currently being built. Please check back soon.

Work through the user stories in order. Each story states the goal and acceptance criteria; its nested tasks retain the detailed implementation and verification steps.
Check the result against this instruction: Copy your 3.1 ending code, renaming both the folder and the Visual Studio solution file
Check the result against this instruction: Build your solution and ensure it compiles without warnings or errors.
With as many animals and possible animals that the zoo has/can have, the Animal class will become unwieldy.
You will define a class that represents a Dingo and have it inherit from the Animal class so that it has access to the Animal class, but also can have its own functionality.
This focused design shows the members or flow relevant to this feature. Keep unchanged members from your preceding checkpoint; follow the tasks below for the order of intermediate edits.
Dingo classpublic class Dingo : Animal
{
public Dingo(string gender, string name, int age, double weight)
{
}
}Animal class to instantiate the Dingopublic Dingo(string gender, string name, int age, double weight)
: base("Dingo", gender, name, age, weight)
{
}Passing in "Dingo" here is necessary because the Animal constructor requires a string for the type of Animal.
// Create Dolly
Animal animal = new Dingo("Female", "Dolly", 4, 35.3);
animal.MakePregnant();
this.comoZoo.AddAnimal(animal);
// Create Dixie.
animal = new Dingo("Female", "Dixie", 3, 33.8);
animal.MakePregnant();
this.comoZoo.AddAnimal(animal);Check the result against this instruction: In the MainWindow, modify the lines of code that instantiate Dolly and Dixie by replacing Animal with Dingo and deleting the type argument.
New Como Zoo buttonDingo constructor's call to base. Ensure that the values of the Dingo constructor match those belowThe Autos window does not handle inheritance constructors well so use the Locals window or hover over values to check them.

Animal classAnimal constructor and the Dingo constructor and return to the MainWindow
The zoo still has platypodes (that's right...that's the plural for platypus) and hummingbirds that need their own functionality.
You will define classes and instantiate animals using inherited classes.
This focused design shows the members or flow relevant to this feature. Keep unchanged members from your preceding checkpoint; follow the tasks below for the order of intermediate edits.
Check the result against this instruction: Add and define classes for Platypus and Hummingbird and have them inherit from the Animal class.
Check the result against this instruction: Build your solution and ensure it compiles without errors or warnings.
Check the result against this instruction: In the Platypus and Hummingbird constructors, call the base constructor and pass in the type string and the proper arguments.
Check the result against this instruction: In the MainWindow, refactor the instantiation of the animals to call their respective classes and remove the type argument.
New Como Zoo buttonPlatypus constructor on the line that calls baseAnimal constructor and the Platypus constructor and back to the MainWindow
New San Diego Zoo
Currently we are relying heavily on using the "type" of animal as a string to perform many of the procedures in the code, but doing that is prone to error.
Now that we have animals being instantiated through their own classes, we can use those classes as a "type" instead of strings.
This focused design shows the members or flow relevant to this feature. Keep unchanged members from your preceding checkpoint; follow the tasks below for the order of intermediate edits.
Type property from the Animal classEat method, change the switch statement to get the type of object and then it's Name fieldswitch (this.GetType().Name)MakePregnant method, when instantiating a baby, delete the argument for TypeReproduce method, change the type reference to GetType and the Name fieldif (this.GetType().Name != "Platypus")Check the result against this instruction: In the Dingo, Hummingbird, and Platypus classes, remove the string argument from base that assigns the type of Animal it is.
FindAnimal and FindPregnantAnimal methods to require an argument of type TypeFindAnimal and FindPregnantAnimal methods, replace the if statement with a statement that checks if the current animal's type is the same as the type passed inif (a.GetType() == type)this.comoZoo.Visitor.FeedAnimal(this.comoZoo.FindAnimal(typeof(Dingo)), this.comoZoo.AnimalSnackMachine);this.sanDiegoZoo.BirthAnimal(this.sanDiegoZoo.FindPregnantAnimal(typeof(Platypus)));Check the result against this instruction: In the MainWindow, replace the strings that are passed in to the FindAnimal and FindPregnantAnimal methods to the typeof whatever animal type needs to be found.
Check the result against this instruction: Build your solution and ensure that there are no errors or warnings.
darlaFeedDingoButton_Click on the line of code that calls FeedAnimalNew Como Zoo button. Click the Darla, feed dingo buttonVisitor property and into the FindAnimal method. Ensure that the type parameter matches the one below
GetType method return matches the one below
birthPlatypusButton_Click on the line that calls BirthAnimalAnimal class in the Reproduce method on the line that checks if the animal is a PlatypusNew San Diego Zoo button. Click the Birth platypus buttonFindPregnantAnimal method. Ensure that the type parameter is a PlatypusFindPregnantAnimal method and ensure the logic check passes for the first animal
Now that we don't have a type field anymore, the baby being instantiated will be a generic Animal type and if it's born will look like an abomination.
You will use a switch statement to determine the type of the animal giving birth and then instantiate a baby animal based on that.
This focused design shows the members or flow relevant to this feature. Keep unchanged members from your preceding checkpoint; follow the tasks below for the order of intermediate edits.
switch (this.GetType().Name)Check the result against this instruction: In the MakePregnant method in the Animal class, inside of the existing if statement, replace the line currently instantiating the baby with a switch statement that uses GetType to get the Name of the type.
case "Dingo":
this.baby = new Dingo("Male", string.Empty, 0, this.Weight * this.babyWeightPercentage);
break;Check the result against this instruction: In the switch statement, if the Name is Dingo, instantiate a type of Dingo. If it is a Platypus, instanti Platypus. If it is a Hummingbird, instantiate a Hummingbird.
MakePregnant method in the Animal class on the switch statementNew Como Zoo button"Dingo" case is hitthis.baby is now an instance of a DingoMakePregnant method in the Animal class on the switch statementNew San Diego Zoo button"Platypus" case is hitthis.baby is now an instance of a PlatypusWe defined the way a Dingo eats but don't have any definition for how a Platypus eats.
You will define how a Platypus eats using inheritance.
This focused design shows the members or flow relevant to this feature. Keep unchanged members from your preceding checkpoint; follow the tasks below for the order of intermediate edits.
Check the result against this instruction: Remove the StashInPouch method from the Animal class and put it inside the Platypus class and add an Eat method that is an override.
Check the result against this instruction: Inside the Eat method in the Platypus class, call the StashInPouch method and pass in the food parameter and then call the Eat method on base and pass in the food parameter.
FeedAnimal method in the Guest class on the line that calls Eat on the animal objectNew San Diego Zoo. Click Dave, feed platypusEat method in the Platypus classEat method. Ensure that the debugger steps into the StashInPouch method in the Platypus class and then the Eat method in the Animal classCurrently when all animals eat their weight gain percentage goes up the same amount, but different type of animals gain weight at different rates.
You will define additional classes that inherit from the Animal class so that Mammals and Birds gain weight differently.
This focused design shows the members or flow relevant to this feature. Keep unchanged members from your preceding checkpoint; follow the tasks below for the order of intermediate edits.
| Category | Percentage | How to verify |
|---|---|---|
Mammal |
0.8 | Food weight multiplied by 0.8 |
Bird |
0.64 | Food weight multiplied by 0.64 |
Mammal and Bird classes and have them inherit from the Animal classDingo classDingo : MammalCheck the result against this instruction: Change the Dingo and Platypus classes to inherit from Mammal and the Hummingbird class to inherit from Bird.
double named eatWeightGainPercentage and assign it the value 0.8eatWeightGainPercentagepublic override double EatWeightGainPercentage
{
get
{
return this.eatWeightGainPercentage;
}
}double named eatWeightGainPercentage and assign it the value 0.64eatWeightGainPercentageeatWeightGainPercentage field and define a virtualEatWeightGainPercentage property that returns 0.0
eatWeightGainPercentage now target theEatWeightGainPercentage property.
This will be done purely for organizational purposes. Moving cs files to other folders in the project will not effect anything.

Name the folder 'Animals'Bird, Dingo, Hummingbird, Mammal, and Platypus into the Animals folder
Eat method in the Animal class on the line that assigns the weightGainNew Como Zoo. Click Darla, feed dingoWeight property. Step into the the EatWeightGainPercentage property in the Mammal classEat method and press F11. Ensure that the weightGain is assigned 0.318Eat method in the Animal class on the line that assigns the weightGainSanDiego Zoo button. Click the Dave, feed platypus buttonWeight property. Step into the the EatWeightGainPercentage property in the Mammal classEat method and press F11. Ensure that the weightGain is assigned 0.0768Check the result against this instruction: Ensure that all code is StyleCop compliant.
Check the result against this instruction: Zip the solution and submit to the Feedback System
Check the result against this instruction: Submit the Feedback System url to the correct assignment in Canvas.
Return to each user story and confirm that you can demonstrate its acceptance criteria. Use the task checkboxes to track completion; a checked box is not a substitute for testing or inspecting the required evidence.
Represent dingoes with a derived class Represent platypuses and hummingbirds with derived classes Find animals using runtime types Construct a newborn of the correct species Let a dingo extend the shared eating behavior Let a platypus stash food before eating Use mammal and bird weight-gain rulesRemove temporary lines used only to demonstrate compile-time errors. Build without errors or warnings, check StyleCop compliance, and rerun the required scenario paths.
Use the submission or attendance instructions in this page. For a Feedback System submission, upload the requested ZIP, review and resolve the feedback, and submit the resulting URL to the matching Canvas activity. For a Canvas quiz, enter only the requested answers; for an oral final, complete the scheduling and attendance steps.