- Each birthing room references its zoo's existing featured animal.
- Feeding through the birthing room changes the weight seen through
FeaturedAnimal. - Both access paths continue to identify the same mother after care is provided.
The class diagram shows the existing structure. The focused object diagram shows Como Zoo before its birthing room is connected to Dolly.
FeaturedAnimal, BirthArea.Animal, and FeaturedAnimal.Baby. The featured animal and its unborn Baby exist; BirthArea.Animal is still null.| Reference | Como Zoo | San Diego Zoo |
|---|---|---|
FeaturedAnimal |
Dolly, Weight 35.3 | Patti, Weight 3.27 |
BirthArea.Animal |
null | null |
FeaturedAnimal.Baby |
Unborn Animal, Weight 3.53 | Unborn Animal, Weight 0.327 |
Keep the existing names Sex, GetIsPregnant, and Animal.Baby. Keep both calls to MakePregnant() in the zoo-creation methods. The existing temperature setup remains unchanged: Como starts at 75.0 and San Diego at 77.0, each using its room's InitialTemperature to set Temperature.
Baby reference.The zoo and birthing room share the mother, but they do not yet have methods to coordinate her delivery.
Have the zoo call its birthing room, and have the room call its doctor. Clear the shared mother's Baby reference when the delivery step completes.
Employee.cs, below the existing fields and inside the Employee class, add this complete method. The birthing room will call it on its Doctor. Its body is empty in Zoo 1.6./// <summary>
/// Represents the doctor's delivery step.
/// </summary>
public void DeliverAnimal()
{
}BirthingRoom.cs, below the existing fields and inside the BirthingRoom class, add this method. The outer if checks whether the room has a mother. The nested if checks whether she is pregnant. Keep the temperature change, doctor's call, and Baby assignment in this order. The baby local is declared but unused in this version./// <summary>
/// Updates the birthing room and mother when a pregnant animal gives birth.
/// </summary>
public void BirthAnimal()
{
Animal baby = null;
if (this.Mother != null)
{
if (this.Mother.GetIsPregnant())
{
this.Temperature += 0.5;
this.Doctor.DeliverAnimal();
this.Mother.Baby = null;
}
}
}Zoo.cs, inside the Zoo class below the existing methods, add this method so the window can start the action through the zoo./// <summary>
/// Starts the birth action in this zoo's birthing room.
/// </summary>
public void BirthAnimal()
{
this.BirthArea.BirthAnimal();
}The birth methods need a window action, and a second click must not feed a mother who has already given birth.
Add a button for each zoo. Check pregnancy before both the additional feeding and the birth call.
MainWindow.xaml, inside comoZooStackPanel immediately after floraFillVendingMachineButton, add the following button.<Button x:Name="birthDingoButton" Content="Give birth to dingo" Click="birthDingoButton_Click"/>
MainWindow.xaml, inside sanDiegoZooStackPanel, add this button immediately after bettyFillVendingMachineButton and before the temperature label.<Button x:Name="birthPlatypusButton" Content="Give birth to platypus" Click="birthPlatypusButton_Click"/>
MainWindow.xaml.cs, add public void birthDingoButton_Click(object sender, RoutedEventArgs e). Use the following body and add XML summary and parameter documentation.if (this.ComoZoo.FeaturedAnimal.GetIsPregnant())
{
this.ComoZoo.FeaturedAnimal.Eat(this.ComoZoo.FeaturedAnimal.Weight * 0.05);
this.ComoZoo.BirthAnimal();
}birthPlatypusButton_Click with the same event-handler parameters and body structure, using SanDiegoZoo in place of ComoZoo. Keep both the Eat and BirthAnimal calls inside the pregnancy check.birthDingoButton_Click before the birth calls.New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.Give birth to dingo. Use F11 to follow the calls into Zoo, BirthingRoom and Employee.this.ComoZoo.FeaturedAnimal.Baby and this.ComoZoo.BirthArea.Mother.Baby are both null.this.ComoZoo.BirthArea.Temperature is 75.5.this.ComoZoo.FeaturedAnimal.Weight. Continue and click Give birth to dingo again. Confirm the weight and this.ComoZoo.BirthArea.Temperature do not change.birthPlatypusButton_Click with a new San Diego Zoo. After delivery, confirm this.SanDiegoZoo.FeaturedAnimal.Baby is null and this.SanDiegoZoo.BirthArea.Temperature is 77.5.Give birth to platypus again. Confirm Patti’s weight and the room temperature stay unchanged.F5 to continue. Stop debugging and remove the breakpoint before the next check.A null or empty message should not erase useful information already shown in the text box.
Use two separate early-return checks before the existing text assignment.
MainWindow.DisplayMessage(string message), add two separate if statements before the existing informationTextBox.Text assignment. Return immediately if message is null. In the second statement, return immediately if message equals string.Empty. Keep the existing text assignment after both checks.MainWindow. Record the current information-box text.this.DisplayMessage(null). Confirm the information-box text stays unchanged.this.DisplayMessage(string.Empty). Confirm the text again stays unchanged.Created San Diego Zoo..F5 to continue. Stop debugging and remove the breakpoint before the next check.FeaturedAnimal with BirthArea.Mother and both feeding handlers call BirthArea.Mother.Eat(foodWeight). Verify both mothers start pregnant and MakePregnant retains its early return and separate Female check.informationTextBox at Height="84" and retain the existing zoo-creation messages. Initial temperatures remain Como 75.0 and San Diego 77.0, with Temperature assigned from InitialTemperature.BirthingRoom.BirthAnimal() is unused in this version. Confirm new methods have XML documentation.