Overview
Activity
Update the Zoo project from checkpoint 3.6 to checkpoint 3.7.
User Story
As a developer, I want to complete the module by integrating the final interfaces, enums, and user-interface behavior so the project demonstrates the programming concepts introduced in Zoo 3.7.
Acceptance Criteria
- Existing files contain the checkpoint changes shown in this walkthrough.
- The solution builds successfully.
- The application starts and the updated behavior can be exercised.
- Names, casing, namespaces, and member signatures match the checkpoint source.
Task List
- Update 3 existing source files.
- Build the solution and resolve any compiler errors.
- Run the application and verify the new behavior.
Exact Casing Matters
Use the filenames, class names, namespaces, method names, property names, and enum values exactly as shown.
Watch Out For
Do not copy build-output folders such as bin, obj, .vs, or package caches into your working project.
Before You Begin
Start with a clean copy of Zoo 3.6 End. Rename the extracted solution folder and solution file for the current checkpoint before making code changes.
Understand the Changes
new instructional files
existing files changed
project-file updates
Files to create
- None
Files to update
ZooScenario/Business Classes/Zoo.csZooScenario/MainWindow.xamlZooScenario/MainWindow.xaml.cs
Create New Files
No new instructional source files are required for this checkpoint.
Update Existing Files
ZooScenario/Business Classes/Zoo.cs
Apply the following code changes:
--- 3.6/ZooScenario/Business Classes/Zoo.cs
+++ 3.7/ZooScenario/Business Classes/Zoo.cs
@@ -28,6 +28,16 @@
/// The maximum number of guests the zoo can accommodate at a given time.
/// </summary>
private int capacity;
+
+ /// <summary>
+ /// The zoo's eaters.
+ /// </summary>
+ private List<IEater> eaters;
+
+ /// <summary>
+ /// The zoo's movers.
+ /// </summary>
+ private List<IMover> movers;
/// <summary>
/// The zoo's featured animal.
@@ -84,6 +94,8 @@
if (capacity > 0)
{
this.Animals = new List<Animal>();
+ this.eaters = new List<IEater>();
+ this.movers = new List<IMover>();
this.AnimalSnackMachine = new VendingMachine(foodPricePerPound, 0.0, 0.00m);
this.BirthArea = new BirthingRoom(doctor);
this.Capacity = capacity;
@@ -539,6 +551,16 @@
{
this.Animals.Add(animal);
+ if (animal is IEater)
+ {
+ this.eaters.Add(animal as IEater);
+ }
+
+ if (animal is IMover)
+ {
+ this.movers.Add(animal as IMover);
+ }
+
if (this.FeaturedAnimal == null)
{
this.featuredAnimal = animal;
@@ -569,6 +591,30 @@
}
return animalsFed;
+ }
+
+ /// <summary>
+ /// Feeds all eaters.
+ /// </summary>
+ /// <returns>The number of eaters that were fed.</returns>
+ public int FeedAllEaters()
+ {
+ int eatersFed = 0;
+
+ if (this.eaters != null)
+ {
+ foreach (IEater eater in this.eaters)
+ {
+ if (eater != null)
+ {
+ Food food = new Food(eater.PortionSize);
+ eater.Eat(food);
+ eatersFed = eatersFed + 1;
+ }
+ }
+ }
+
+ return eatersFed;
}
/// <summary>
ZooScenario/MainWindow.xaml
Apply the following code changes:
--- 3.6/ZooScenario/MainWindow.xaml
+++ 3.7/ZooScenario/MainWindow.xaml
@@ -66,6 +66,7 @@
<CheckBox x:Name="dingoPregnantCheckBox" Content="Pregnant" Margin="3"/>
<Button x:Name="addDingoFromTextBoxesButton" Content="Add dingo from text boxes" Click="addDingoFromTextBoxesButton_Click"/>
<Button x:Name="feedAllSanDiegoAnimalsButton" Content="Feed all animals" Click="feedAllSanDiegoAnimalsButton_Click"/>
+ <Button x:Name="feedAllSanDiegoEatersButton" Content="Feed all eaters" Click="feedAllSanDiegoEatersButton_Click"/>
<Button x:Name="getSanDiegoAnimalCountButton" Content="Get animal count" Click="getSanDiegoAnimalCountButton_Click"/>
<Button x:Name="getSanDiegoAverageWeightButton" Content="Get average weight" Click="getSanDiegoAverageWeightButton_Click"/>
<TextBlock Text="Platypus fish tank:" Margin="3,10,3,0"/>
ZooScenario/MainWindow.xaml.cs
Apply the following code changes:
--- 3.6/ZooScenario/MainWindow.xaml.cs
+++ 3.7/ZooScenario/MainWindow.xaml.cs
@@ -634,5 +634,23 @@
MessageBox.Show("Create the San Diego Zoo before filling the animal snack machine.", "Zoo not created");
}
}
+
+ /// <summary>
+ /// Feeds all the eaters at the San Diego Zoo.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void feedAllSanDiegoEatersButton_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ int eatersFed = this.sanDiegoZoo.FeedAllEaters();
+ this.informationTextBox.Text = "Fed " + eatersFed + " San Diego Zoo eaters.";
+ }
+ catch (NullReferenceException)
+ {
+ MessageBox.Show("Create the San Diego Zoo before feeding all eaters.", "Zoo not created");
+ }
+ }
}
}
Check Your Work
- Save all files.
- Build the solution.
- Resolve compiler errors before continuing.
- Run the application.
- Exercise the new or updated behavior associated with Zoo 3.7.
- Compare your filenames, namespaces, signatures, and key values with the code shown above.
Summary
You updated the project from Zoo 3.6 End to Zoo 3.7 End by creating the required files, modifying only the files with meaningful source changes, and verifying the completed application.