Overview

Activity

Update the Zoo project from checkpoint 3.1 to checkpoint 3.2.

User Story

As a developer, I want to extend the Animal class and use the new behavior from the main window so the project demonstrates the programming concepts introduced in Zoo 3.2.

Acceptance Criteria

Task List

  1. Update 2 existing source files.
  2. Build the solution and resolve any compiler errors.
  3. 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.1 End. Rename the extracted solution folder and solution file for the current checkpoint before making code changes.

Understand the Changes

0
new instructional files
2
existing files changed
0
project-file updates

Files to create

Files to update

Create New Files

No new instructional source files are required for this checkpoint.

Update Existing Files

Temporary screenshot for Zoo 3.2: Update Existing Files
Temporary screenshot location: Update Existing Files.

ZooScenario/Business Classes/Animal.cs

Apply the following code changes:

--- 3.1/ZooScenario/Business Classes/Animal.cs
+++ 3.2/ZooScenario/Business Classes/Animal.cs
@@ -54,14 +54,11 @@
         /// <param name="weight">The animal weight.</param>
         public Animal(string name, string type, string gender, int age, double weight)
         {
-            if (age >= 0 && weight > 0)
-            {
-                this.Age = age;
-                this.Gender = gender;
-                this.Name = name;
-                this.Type = type;
-                this.Weight = weight;
-            }
+            this.Age = age;
+            this.Gender = gender;
+            this.Name = name;
+            this.Type = type;
+            this.Weight = weight;
         }
 
         /// <summary>
@@ -76,10 +73,12 @@
 
             set
             {
-                if (value >= 0)
-                {
-                    this.age = value;
-                }
+                if (value < 0)
+                {
+                    throw new ArgumentException("Age cannot be negative.");
+                }
+
+                this.age = value;
             }
         }
 
@@ -111,22 +110,28 @@
 
             set
             {
-                if (value != null)
-                {
-                    string cleanedGender = value.Trim().ToLower();
-
-                    if (cleanedGender == "female")
-                    {
-                        this.gender = "Female";
-                    }
-                    else if (cleanedGender == "male")
-                    {
-                        this.gender = "Male";
-                    }
-                    else if (cleanedGender == "unknown")
-                    {
-                        this.gender = "Unknown";
-                    }
+                if (value == null)
+                {
+                    throw new ArgumentException("Gender is required.");
+                }
+
+                string cleanedGender = value.Trim().ToLower();
+
+                if (cleanedGender == "female")
+                {
+                    this.gender = "Female";
+                }
+                else if (cleanedGender == "male")
+                {
+                    this.gender = "Male";
+                }
+                else if (cleanedGender == "unknown")
+                {
+                    this.gender = "Unknown";
+                }
+                else
+                {
+                    throw new ArgumentException("Gender must be Female, Male, or Unknown.");
                 }
             }
         }
@@ -143,10 +148,12 @@
 
             set
             {
-                if (value != null && value.Trim() != string.Empty)
-                {
-                    this.name = value.Trim();
-                }
+                if (value == null || value.Trim() == string.Empty)
+                {
+                    throw new ArgumentException("Name is required.");
+                }
+
+                this.name = value.Trim();
             }
         }
 
@@ -162,26 +169,28 @@
 
             set
             {
-                if (value != null && value.Trim() != string.Empty)
-                {
-                    string cleanedType = value.Trim().ToLower();
-
-                    if (cleanedType == "dingo")
-                    {
-                        this.type = "Dingo";
-                    }
-                    else if (cleanedType == "hummingbird")
-                    {
-                        this.type = "Hummingbird";
-                    }
-                    else if (cleanedType == "platypus")
-                    {
-                        this.type = "Platypus";
-                    }
-                    else
-                    {
-                        this.type = value.Trim();
-                    }
+                if (value == null || value.Trim() == string.Empty)
+                {
+                    throw new ArgumentException("Type is required.");
+                }
+
+                string cleanedType = value.Trim().ToLower();
+
+                if (cleanedType == "dingo")
+                {
+                    this.type = "Dingo";
+                }
+                else if (cleanedType == "hummingbird")
+                {
+                    this.type = "Hummingbird";
+                }
+                else if (cleanedType == "platypus")
+                {
+                    this.type = "Platypus";
+                }
+                else
+                {
+                    throw new ArgumentException("Type must be Dingo, Hummingbird, or Platypus.");
                 }
             }
         }
@@ -198,10 +207,12 @@
 
             set
             {
-                if (value > 0)
-                {
-                    this.weight = value;
-                }
+                if (value <= 0)
+                {
+                    throw new ArgumentException("Weight must be greater than zero.");
+                }
+
+                this.weight = value;
             }
         }
 

ZooScenario/MainWindow.xaml.cs

Apply the following code changes:

--- 3.1/ZooScenario/MainWindow.xaml.cs
+++ 3.2/ZooScenario/MainWindow.xaml.cs
@@ -90,47 +90,29 @@
 
             if (this.sanDiegoZoo != null)
             {
-                string cleanedName = nameText.Trim();
-                string cleanedGender = genderText.Trim().ToLower();
-                string cleanedAge = ageText.Trim();
-                string cleanedWeight = weightText.Trim();
-
-                if (cleanedName == string.Empty)
+                try
                 {
-                    message = "Enter a name for the dingo.";
+                    int age = int.Parse(ageText.Trim());
+                    double weight = double.Parse(weightText.Trim());
+                    Animal dingo = this.CreateAnimal(nameText, "Dingo", genderText, age, weight, isPregnant);
+                    this.sanDiegoZoo.AddAnimal(dingo);
+                    message = dingo.DisplayName + " was added to the San Diego Zoo.";
                 }
-                else if (cleanedGender != "female" && cleanedGender != "male")
+                catch (FormatException)
                 {
-                    message = "Enter female or male for the dingo gender.";
+                    MessageBox.Show("Age must be a whole number and weight must be a number.", "Invalid dingo entry");
+                    message = "The dingo was not added.";
                 }
-                else if (!this.IsWholeNumberText(cleanedAge))
+                catch (OverflowException)
                 {
-                    message = "Enter a whole number for the dingo age.";
+                    MessageBox.Show("Age or weight is too large.", "Invalid dingo entry");
+                    message = "The dingo was not added.";
                 }
-                else if (!this.IsDecimalNumberText(cleanedWeight))
+                catch (ArgumentException ex)
                 {
-                    message = "Enter a number for the dingo weight.";
+                    MessageBox.Show(ex.Message, "Invalid dingo entry");
+                    message = "The dingo was not added.";
                 }
-                else
-                {
-                    int age = int.Parse(cleanedAge);
-                    double weight = double.Parse(cleanedWeight);
-
-                    if (age < 0)
-                    {
-                        message = "Enter a nonnegative age for the dingo.";
-                    }
-                    else if (weight <= 0)
-                    {
-                        message = "Enter a positive weight for the dingo.";
-                    }
-                    else
-                    {
-                        Animal dingo = this.CreateAnimal(cleanedName, "Dingo", cleanedGender, age, weight, isPregnant);
-                        this.sanDiegoZoo.AddAnimal(dingo);
-                        message = dingo.DisplayName + " was added to the San Diego Zoo.";
-                    }
-                }
             }
 
             return message;
@@ -143,8 +125,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void feedAllComoAnimalsButton_Click(object sender, RoutedEventArgs e)
         {
-            int animalsFed = this.comoZoo.FeedAllAnimals();
-            this.informationTextBox.Text = "Fed " + animalsFed + " Como Zoo animals.";
+            try
+            {
+                int animalsFed = this.comoZoo.FeedAllAnimals();
+                this.informationTextBox.Text = "Fed " + animalsFed + " Como Zoo animals.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before feeding animals.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -154,8 +143,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void feedAllSanDiegoAnimalsButton_Click(object sender, RoutedEventArgs e)
         {
-            int animalsFed = this.sanDiegoZoo.FeedAllAnimals();
-            this.informationTextBox.Text = "Fed " + animalsFed + " San Diego Zoo animals.";
+            try
+            {
+                int animalsFed = this.sanDiegoZoo.FeedAllAnimals();
+                this.informationTextBox.Text = "Fed " + animalsFed + " San Diego Zoo animals.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before feeding animals.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -165,7 +161,14 @@
         /// <param name="e">The event arguments for the event.</param>
         private void getComoAnimalCountButton_Click(object sender, RoutedEventArgs e)
         {
-            this.informationTextBox.Text = "Como Zoo animal count: " + this.comoZoo.AnimalCount + ".";
+            try
+            {
+                this.informationTextBox.Text = "Como Zoo animal count: " + this.comoZoo.AnimalCount + ".";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before getting the animal count.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -175,7 +178,14 @@
         /// <param name="e">The event arguments for the event.</param>
         private void getComoAverageWeightButton_Click(object sender, RoutedEventArgs e)
         {
-            this.informationTextBox.Text = "Como Zoo average animal weight: " + this.comoZoo.AverageAnimalWeight + ".";
+            try
+            {
+                this.informationTextBox.Text = "Como Zoo average animal weight: " + this.comoZoo.AverageAnimalWeight + ".";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before getting the average animal weight.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -185,7 +195,14 @@
         /// <param name="e">The event arguments for the event.</param>
         private void getSanDiegoAnimalCountButton_Click(object sender, RoutedEventArgs e)
         {
-            this.informationTextBox.Text = "San Diego Zoo animal count: " + this.sanDiegoZoo.AnimalCount + ".";
+            try
+            {
+                this.informationTextBox.Text = "San Diego Zoo animal count: " + this.sanDiegoZoo.AnimalCount + ".";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before getting the animal count.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -195,85 +212,14 @@
         /// <param name="e">The event arguments for the event.</param>
         private void getSanDiegoAverageWeightButton_Click(object sender, RoutedEventArgs e)
         {
-            this.informationTextBox.Text = "San Diego Zoo average animal weight: " + this.sanDiegoZoo.AverageAnimalWeight + ".";
-        }
-
-        /// <summary>
-        /// Determines whether text can be read as a decimal number.
-        /// </summary>
-        /// <param name="text">The text to check.</param>
-        /// <returns>A value indicating whether the text can be read as a decimal number.</returns>
-        private bool IsDecimalNumberText(string text)
-        {
-            string cleanedText = text.Trim();
-            bool isNumberText = cleanedText != string.Empty;
-            int decimalPointCount = 0;
-            int startIndex = 0;
-
-            if (cleanedText.Length > 0 && cleanedText[0] == '-')
-            {
-                startIndex = 1;
-            }
-
-            if (startIndex == cleanedText.Length)
-            {
-                isNumberText = false;
-            }
-
-            for (int i = startIndex; i < cleanedText.Length && isNumberText; i++)
-            {
-                char currentCharacter = cleanedText[i];
-
-                if (currentCharacter == '.')
-                {
-                    decimalPointCount++;
-
-                    if (decimalPointCount > 1)
-                    {
-                        isNumberText = false;
-                    }
-                }
-                else if (currentCharacter < '0' || currentCharacter > '9')
-                {
-                    isNumberText = false;
-                }
-            }
-
-            return isNumberText;
-        }
-
-        /// <summary>
-        /// Determines whether text can be read as a whole number.
-        /// </summary>
-        /// <param name="text">The text to check.</param>
-        /// <returns>A value indicating whether the text can be read as a whole number.</returns>
-        private bool IsWholeNumberText(string text)
-        {
-            string cleanedText = text.Trim();
-            bool isNumberText = cleanedText != string.Empty;
-            int startIndex = 0;
-
-            if (cleanedText.Length > 0 && cleanedText[0] == '-')
-            {
-                startIndex = 1;
-            }
-
-            if (startIndex == cleanedText.Length)
-            {
-                isNumberText = false;
-            }
-
-            for (int i = startIndex; i < cleanedText.Length && isNumberText; i++)
-            {
-                char currentCharacter = cleanedText[i];
-
-                if (currentCharacter < '0' || currentCharacter > '9')
-                {
-                    isNumberText = false;
-                }
-            }
-
-            return isNumberText;
+            try
+            {
+                this.informationTextBox.Text = "San Diego Zoo average animal weight: " + this.sanDiegoZoo.AverageAnimalWeight + ".";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before getting the average animal weight.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -283,8 +229,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void wakeAllComoAnimalsButton_Click(object sender, RoutedEventArgs e)
         {
-            int animalsWoken = this.comoZoo.WakeAllAnimals();
-            this.informationTextBox.Text = "Woke " + animalsWoken + " Como Zoo animals.";
+            try
+            {
+                int animalsWoken = this.comoZoo.WakeAllAnimals();
+                this.informationTextBox.Text = "Woke " + animalsWoken + " Como Zoo animals.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before waking animals.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -294,8 +247,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void wakeAllSanDiegoAnimalsButton_Click(object sender, RoutedEventArgs e)
         {
-            int animalsWoken = this.sanDiegoZoo.WakeAllAnimals();
-            this.informationTextBox.Text = "Woke " + animalsWoken + " San Diego Zoo animals.";
+            try
+            {
+                int animalsWoken = this.sanDiegoZoo.WakeAllAnimals();
+                this.informationTextBox.Text = "Woke " + animalsWoken + " San Diego Zoo animals.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before waking animals.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -349,8 +309,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void opencomoZooButton_Click(object sender, RoutedEventArgs e)
         {
-            this.comoZoo.OpenForVisitor(1);
-            this.informationTextBox.Text = "The Como Zoo is open for " + this.comoZoo.Visitor.Name + ".";
+            try
+            {
+                this.comoZoo.OpenForVisitor(1);
+                this.informationTextBox.Text = "The Como Zoo is open for " + this.comoZoo.Visitor.Name + ".";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before opening it.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -360,9 +327,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void feedComoAnimalButton_Click(object sender, RoutedEventArgs e)
         {
-            double foodWeight = this.comoZoo.FeedFeaturedAnimal();
-            this.informationTextBox.Text = this.comoZoo.Visitor.Name + " fed " + this.comoZoo.FeaturedAnimal.Name
-                + " " + foodWeight + " pounds of food.";
+            try
+            {
+                double foodWeight = this.comoZoo.FeedFeaturedAnimal();
+                this.informationTextBox.Text = this.comoZoo.Visitor.Name + " fed " + this.comoZoo.FeaturedAnimal.Name + " " + foodWeight + " pounds of food.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before feeding an animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -372,13 +345,20 @@
         /// <param name="e">The event arguments for the event.</param>
         private void careForComoAnimalButton_Click(object sender, RoutedEventArgs e)
         {
-            Animal assignedAnimal = this.comoZoo.BirthArea.Doctor.AssignedAnimal;
-
-            this.comoZoo.BirthArea.Doctor.FeedAnimal();
-            this.informationTextBox.Text = this.comoZoo.BirthArea.Doctor.Name + " cared for "
-                + assignedAnimal.Name + ". Featured animal weight: "
-                + this.comoZoo.FeaturedAnimal.Weight + ". Birthing room mother weight: "
-                + this.comoZoo.BirthArea.Mother.Weight + ".";
+            try
+            {
+                Animal assignedAnimal = this.comoZoo.BirthArea.Doctor.AssignedAnimal;
+
+                this.comoZoo.BirthArea.Doctor.FeedAnimal();
+                this.informationTextBox.Text = this.comoZoo.BirthArea.Doctor.Name + " cared for "
+                    + assignedAnimal.Name + ". Featured animal weight: "
+                    + this.comoZoo.FeaturedAnimal.Weight + ". Birthing room mother weight: "
+                    + this.comoZoo.BirthArea.Mother.Weight + ".";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before caring for an animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -388,8 +368,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void prepareComoBirthingRoomButton_Click(object sender, RoutedEventArgs e)
         {
-            this.comoZoo.PrepareBirthingRoom(1.5);
-            this.informationTextBox.Text = "The Como Zoo birthing room is ready.";
+            try
+            {
+                this.comoZoo.PrepareBirthingRoom(1.5);
+                this.informationTextBox.Text = "The Como Zoo birthing room is ready.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before preparing the birthing room.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -399,8 +386,16 @@
         /// <param name="e">The event arguments for the event.</param>
         private void fillComoVendingMachineButton_Click(object sender, RoutedEventArgs e)
         {
-            this.comoZoo.FillAnimalSnackMachine(40.0, 35.0);
-            this.informationTextBox.Text = "The Como Zoo animal snack machine has been filled.";
+            try
+            {
+                this.comoZoo.FillAnimalSnackMachine(40.0, 35.0);
+                this.informationTextBox.Text = "The Como Zoo animal snack machine has been filled.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before filling the animal snack machine.", "Zoo not created");
+                return;
+            }
         }
 
         /// <summary>
@@ -410,8 +405,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void moveDingoLeftButton_Click(object sender, RoutedEventArgs e)
         {
-            this.comoZoo.MoveFeaturedAnimalLeft();
-            this.penDisplayTextBox.Text = this.comoZoo.DingoPenDisplay;
+            try
+            {
+                this.comoZoo.MoveFeaturedAnimalLeft();
+                this.penDisplayTextBox.Text = this.comoZoo.DingoPenDisplay;
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before moving the featured animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -421,8 +423,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void moveDingoRightButton_Click(object sender, RoutedEventArgs e)
         {
-            this.comoZoo.MoveFeaturedAnimalRight();
-            this.penDisplayTextBox.Text = this.comoZoo.DingoPenDisplay;
+            try
+            {
+                this.comoZoo.MoveFeaturedAnimalRight();
+                this.penDisplayTextBox.Text = this.comoZoo.DingoPenDisplay;
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the Como Zoo before moving the featured animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -432,8 +441,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void movePlatypusDownButton_Click(object sender, RoutedEventArgs e)
         {
-            this.sanDiegoZoo.MoveFeaturedAnimalDown();
-            this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
+            try
+            {
+                this.sanDiegoZoo.MoveFeaturedAnimalDown();
+                this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before moving the featured animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -443,8 +459,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void movePlatypusLeftButton_Click(object sender, RoutedEventArgs e)
         {
-            this.sanDiegoZoo.MoveFeaturedAnimalLeft();
-            this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
+            try
+            {
+                this.sanDiegoZoo.MoveFeaturedAnimalLeft();
+                this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before moving the featured animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -454,8 +477,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void movePlatypusRightButton_Click(object sender, RoutedEventArgs e)
         {
-            this.sanDiegoZoo.MoveFeaturedAnimalRight();
-            this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
+            try
+            {
+                this.sanDiegoZoo.MoveFeaturedAnimalRight();
+                this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before moving the featured animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -465,8 +495,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void movePlatypusUpButton_Click(object sender, RoutedEventArgs e)
         {
-            this.sanDiegoZoo.MoveFeaturedAnimalUp();
-            this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
+            try
+            {
+                this.sanDiegoZoo.MoveFeaturedAnimalUp();
+                this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before moving the featured animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -476,8 +513,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void opensanDiegoZooButton_Click(object sender, RoutedEventArgs e)
         {
-            this.sanDiegoZoo.OpenForVisitor(2);
-            this.informationTextBox.Text = "The San Diego Zoo is open for " + this.sanDiegoZoo.Visitor.Name + ".";
+            try
+            {
+                this.sanDiegoZoo.OpenForVisitor(2);
+                this.informationTextBox.Text = "The San Diego Zoo is open for " + this.sanDiegoZoo.Visitor.Name + ".";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before opening it.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -487,9 +531,16 @@
         /// <param name="e">The event arguments for the event.</param>
         private void feedSanDiegoAnimalButton_Click(object sender, RoutedEventArgs e)
         {
-            double foodWeight = this.sanDiegoZoo.FeedFeaturedAnimal();
-            this.informationTextBox.Text = this.sanDiegoZoo.Visitor.Name + " fed " + this.sanDiegoZoo.FeaturedAnimal.Name
-                + " " + foodWeight + " pounds of food.";
+            try
+            {
+                double foodWeight = this.sanDiegoZoo.FeedFeaturedAnimal();
+                this.informationTextBox.Text = this.sanDiegoZoo.Visitor.Name + " fed " + this.sanDiegoZoo.FeaturedAnimal.Name
+                    + " " + foodWeight + " pounds of food.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before feeding an animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -499,13 +550,20 @@
         /// <param name="e">The event arguments for the event.</param>
         private void careForSanDiegoAnimalButton_Click(object sender, RoutedEventArgs e)
         {
-            Animal assignedAnimal = this.sanDiegoZoo.BirthArea.Doctor.AssignedAnimal;
-
-            this.sanDiegoZoo.BirthArea.Doctor.FeedAnimal();
-            this.informationTextBox.Text = this.sanDiegoZoo.BirthArea.Doctor.Name + " cared for "
-                + assignedAnimal.Name + ". Featured animal weight: "
-                + this.sanDiegoZoo.FeaturedAnimal.Weight + ". Birthing room mother weight: "
-                + this.sanDiegoZoo.BirthArea.Mother.Weight + ".";
+            try
+            {
+                Animal assignedAnimal = this.sanDiegoZoo.BirthArea.Doctor.AssignedAnimal;
+
+                this.sanDiegoZoo.BirthArea.Doctor.FeedAnimal();
+                this.informationTextBox.Text = this.sanDiegoZoo.BirthArea.Doctor.Name + " cared for "
+                    + assignedAnimal.Name + ". Featured animal weight: "
+                    + this.sanDiegoZoo.FeaturedAnimal.Weight + ". Birthing room mother weight: "
+                    + this.sanDiegoZoo.BirthArea.Mother.Weight + ".";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before caring for an animal.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -515,8 +573,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void prepareSanDiegoBirthingRoomButton_Click(object sender, RoutedEventArgs e)
         {
-            this.sanDiegoZoo.PrepareBirthingRoom(0.75);
-            this.informationTextBox.Text = "The San Diego Zoo birthing room is ready.";
+            try
+            {
+                this.sanDiegoZoo.PrepareBirthingRoom(0.75);
+                this.informationTextBox.Text = "The San Diego Zoo birthing room is ready.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before preparing the birthing room.", "Zoo not created");
+            }
         }
 
         /// <summary>
@@ -526,8 +591,15 @@
         /// <param name="e">The event arguments for the event.</param>
         private void fillSanDiegoVendingMachineButton_Click(object sender, RoutedEventArgs e)
         {
-            this.sanDiegoZoo.FillAnimalSnackMachine(25.0, 25.0);
-            this.informationTextBox.Text = "The San Diego Zoo animal snack machine has been filled.";
+            try
+            {
+                this.sanDiegoZoo.FillAnimalSnackMachine(25.0, 25.0);
+                this.informationTextBox.Text = "The San Diego Zoo animal snack machine has been filled.";
+            }
+            catch (NullReferenceException)
+            {
+                MessageBox.Show("Create the San Diego Zoo before filling the animal snack machine.", "Zoo not created");
+            }
         }
     }
 }

Check Your Work

Temporary screenshot for Zoo 3.2: Check Your Work
Temporary screenshot location: Check Your Work.
  1. Save all files.
  2. Build the solution.
  3. Resolve compiler errors before continuing.
  4. Run the application.
  5. Exercise the new or updated behavior associated with Zoo 3.2.
  6. Compare your filenames, namespaces, signatures, and key values with the code shown above.

Summary

You updated the project from Zoo 3.1 End to Zoo 3.2 End by creating the required files, modifying only the files with meaningful source changes, and verifying the completed application.