2.3 Zoo Learning Activity

Zoo 2.3 — Prepare your project

Continue from your completed Zoo 2.2. Como keeps its four-space pen. San Diego replaces its pen with a three-row, four-column tank. Both areas will hold a mother and, after birth, a stationary baby.

1.Copy the previous version
A Copy your completed Zoo 2.2 folder, rename the copy and solution to Zoo 2.3 using your last name, open the copied solution, and restore packages

Keep the Programming Concepts 2 window title.

Starting 2.2 structure: each Zoo refers to a Pen; MainWindow displays and moves pen occupants.
Starting class structure — Zoo 2.2
  • New
  • Changed
  • Removed
Represent San Diego’s tank
2.Add Tank.cs and connect it to Zoo
A Add Tank to Business Classes

Use the focused Tank class diagram below to declare Animal, StartingColumn, StartingRow, and TankSpaces. Copy the existing public-field StyleCop suppression attribute from Pen. Add using System; above the namespace if the class template has not already supplied it; GetDisplayLocation uses Environment.NewLine. Keep the class inside namespace ZooScenario. Add the Tank field to Zoo; keep its Pen field for Como. Use the existing XML-documentation style for new fields and methods.

The new Tank class uses public fields and methods. TankSpaces is Animal comma-array notation for two dimensions. MoveAnimal accepts a string; MoveAnimalInTank accepts two integers. No ClearLocation method is added.
Tank — fields and signatures for this lesson
  • New
  • Changed
  • Removed
Expression for new Animal[3, 4] Meaning
TankSpaces.GetLength(0) 3 rows; valid indexes 0–2
TankSpaces.GetLength(1) 4 columns; valid indexes 0–3
TankSpaces.Length 12 total spaces
TankSpaces[1, 1] Second row, second column
3.Check both coordinate bounds
A Implement IsValidLocation(row, column)

Use the diagram to return true only when both indexes are valid. GetLength arguments identify dimensions, not particular rows or columns.

Both coordinates must be inside their dimension lengths. The upper bounds are exclusive.
Check both coordinate bounds — Tank.IsValidLocation
  • New
  • Changed
  • Removed
4.Check membership with foreach
A Implement ContainsAnimal(animal)

Use foreach (Animal tankAnimal in this.TankSpaces). Start with false, skip the search when animal is null, and inspect each tankAnimal reference. Set the result to true and break when the references match. Return the result after the search.

Foreach tests reference membership, stopping at the first match. A null animal returns false.
Check membership with foreach — Tank.ContainsAnimal
  • New
  • Changed
  • Removed
5.Find the row
A Implement FindAnimalRow(animal) from its activity diagram

Initialize foundRow to -1. A match exits the inner loop; the following decision exits the outer loop. Preserve the first match.

FindAnimalRow scans rows then columns, returns the matching row, and breaks out of both loops after a match.
Find the row — Tank.FindAnimalRow
  • New
  • Changed
  • Removed
6.Find the column
A Implement FindAnimalColumn(animal) using its separate diagram

Return the column index, not the row index. Null and absent animals return -1.

FindAnimalColumn scans rows then columns, returns the matching column, and breaks out of both loops after a match.
Find the column — Tank.FindAnimalColumn
  • New
  • Changed
  • Removed
7.Describe the mother’s location
A Implement GetAnimalLocation(animal)

Call ContainsAnimal before searching for coordinates. Keep array indexes zero-based; add one only when constructing the displayed row and column numbers.

Membership is checked with foreach before coordinate searches build the one-based location description.
Describe the mother’s location — Tank.GetAnimalLocation
  • New
  • Changed
  • Removed
8.Place the mother
A Implement PlaceAnimal

Validate the stored mother and starting coordinates, then assign the existing reference. The creation method must allocate TankSpaces before this method runs.

Initial placement stores the existing mother reference at a valid starting coordinate.
Place the mother — Tank.PlaceAnimal
  • New
  • Changed
  • Removed
9.Build the tank map
A Implement GetDisplayLocation

Check every array element with nested for loops. Append X for the mother, x for another non-null occupant, and - for an empty entry. Add spaces between columns and Environment.NewLine between rows, without trailing separators. Environment.NewLine supplies the line break between the rows of the displayed string.

Tank display builds X for the mother, x for the baby, spaces between columns and newlines between rows.
Build the tank map — Tank.GetDisplayLocation
  • New
  • Changed
  • Removed
10.Implement Tank.MoveAnimalInTank
A Add the public method with int rowChange and int columnChange parameters

Use its activity diagram to find the mother, calculate the destination, check the current location and destination, and update the two array entries only when the destination is empty. These parameters are changes such as 0 and 1; they are not absolute destination indexes.

Tank.MoveAnimalInTank receives integer changes, checks bounds before array access, and moves only the mother into an empty space.
Tank.MoveAnimalInTank — update the array
  • New
  • Changed
  • Removed
11.Select the tank’s movement direction
A After implementing MoveAnimalInTank, add public void MoveAnimal(string direction) to Tank.cs

Keep the numeric movement logic in MoveAnimalInTank. Follow the switch activity: each recognized direction calls MoveAnimalInTank with the two integer changes shown, then breaks. This method only chooses the movement request. Leave an unrecognized direction without a movement call.

Tank.MoveAnimal selects a direction with switch and delegates the numeric change to MoveAnimalInTank. Unmatched directions do nothing.
Tank.MoveAnimal — select a direction
  • New
  • Changed
  • Removed
Keep the baby safe
12.Update Pen.GetDisplayLocation
A Keep the existing for loop and spacing

Replace the occupied-space decision with the mother/baby/empty decisions in the diagram. Do not identify the baby by name or position; the mother may visit index 0 before birth.

The existing pen loop gains the mother/baby distinction and keeps its original spacing.
Pen map markers
  • New
  • Changed
  • Removed
13.Rename the existing pen movement method
A In Pen.cs, edit only the existing method declaration: change public void MoveAnimal(int positionChange) to public void MoveAnimalInPen(int positionChange)

Do not use Rename refactoring or Replace All, and do not change the existing callers during this step. Old calls temporarily refer to the removed integer signature; complete the wrapper, window helper, and arrow-handler steps before expecting the project to build. Keep the integer parameter and movement calculations. Add the empty-destination check after IsValidPosition, as shown in the activity diagram. This edit preserves the mother reference and protects the baby’s occupied space.

At the Pen rename step, a blue changed marker precedes MoveAnimalInPen. Only the added InPen suffix is bold blue. Its integer parameter and return type are unchanged. Other methods are abbreviated.
Pen — rename the original method; blue highlights the added InPen suffix
  • New
  • Changed
  • Removed
Pen.MoveAnimalInPen receives an integer change and checks bounds and occupancy before changing array entries.
Pen.MoveAnimalInPen — update the array
  • New
  • Changed
  • Removed
14.Add Pen.MoveAnimal(string direction)
A After renaming the original method, add a new public void MoveAnimal(string direction) method

The original movement code now belongs to MoveAnimalInPen; do not duplicate that code in the new method. The existing window helper will be updated below to pass a string; finish those caller edits before building. Follow the switch diagram to call MoveAnimalInPen(-1) for "Left" and MoveAnimalInPen(1) for "Right", with break after each case. Keep the two method names distinct so each method has one clear job.

At the next Pen step, a green new marker identifies MoveAnimal with a string direction parameter. The previously renamed MoveAnimalInPen retains its integer parameter.
Pen — add the direction wrapper; keep the renamed movement method
  • New
  • Changed
  • Removed
Pen.MoveAnimal selects a direction with switch and delegates the numeric change to MoveAnimalInPen. Unmatched directions do nothing.
Pen.MoveAnimal — select a direction
  • New
  • Changed
  • Removed
Count the occupants
15.Add Zoo.CountAnimals
A Add the returning method to Zoo.cs, following the class and activity diagrams

Start an int variable named count at zero. For each occupied entry, count++ increases that number by one. If Pen exists, foreach through Pen.PenSpaces and increment only for non-null entries. Independently check Tank and do the same for Tank.TankSpaces. Return count. Do not add counting methods to Pen, Tank, or Animal. The existing informationTextBox will announce the count after zoo creation, successful birth, and each movement attempt. Put Environment.NewLine before the count so it appears on its own line.

At the counting step, Zoo gains the public CountAnimals method returning int. Pen and Tank already exist at this point.
Zoo — add the animal count method
  • New
  • Changed
  • Removed
Zoo.CountAnimals counts occupied entries in each existing area. It does not count null slots or the separate FeaturedAnimal reference.
Zoo.CountAnimals activity
  • New
  • Changed
  • Removed
Connect the tank and the window
16.Add Zoo.MoveFeaturedAnimal
A In Zoo.cs, add public void MoveFeaturedAnimal(string direction)

Follow the diagram to forward direction to Pen.MoveAnimal when Pen exists, otherwise to Tank.MoveAnimal when Tank exists. Keep control updates in MainWindow. Como has a pen; San Diego has a tank.

At the forwarding step, Zoo gains MoveFeaturedAnimal with one string parameter. The count method was added earlier.
Zoo — add the forwarding method
  • New
  • Changed
  • Removed
Zoo.MoveFeaturedAnimal forwards its string argument to the existing Pen or Tank. This design uses no Area inheritance or enums.
Zoo.MoveFeaturedAnimal — forward the direction
  • New
  • Changed
  • Removed
17.Replace San Diego’s pen controls
A In MainWindow.xaml, replace the Animal pen label and its horizontal display/button StackPanel inside sanDiegoZooStackPanel with this complete block

Keep the temperature controls below it and keep Como’s controls unchanged. Removing sanDiegoPenDisplayTextBox temporarily leaves an outdated C# reference; replace that reference when updating DisplayAnimalArea below.

<TextBlock Text="Fish tank:" Margin="3,10,3,0"/>
<StackPanel Orientation="Horizontal">
    <TextBox x:Name="sanDiegoTankDisplayTextBox" Margin="5,5,10,5" Padding="5" FontFamily="Consolas" FontSize="24" Height="99" Width="109" HorizontalAlignment="Left" IsReadOnly="True" TextWrapping="NoWrap" AcceptsReturn="True" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled"/>
    <Grid Margin="10,5,5,5">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="moveSanDiegoZooAnimalUpButton" Width="25" FontSize="16" Grid.Row="0" Grid.Column="1" Content="^" Click="moveSanDiegoZooAnimalUpButton_Click"/>
        <Button x:Name="moveSanDiegoZooAnimalDownButton" Width="25" FontSize="16" Grid.Row="2" Grid.Column="1" Content="v" Click="moveSanDiegoZooAnimalDownButton_Click"/>
        <Button x:Name="moveSanDiegoZooAnimalLeftButton" Width="25" FontSize="16" FontWeight="Bold" Grid.Row="1" Grid.Column="0" Content="&lt;" Click="moveSanDiegoZooAnimalLeftButton_Click"/>
        <Button x:Name="moveSanDiegoZooAnimalRightButton" Width="25" FontSize="16" FontWeight="Bold" Grid.Row="1" Grid.Column="2" Content="&gt;" Click="moveSanDiegoZooAnimalRightButton_Click"/>
    </Grid>
</StackPanel>
18.Rename DisplayPen using Visual Studio
A Place the cursor on DisplayPen in MainWindow.xaml.cs and press Ctrl+R, Ctrl+R

Rename it to DisplayAnimalArea and apply the rename to its references. This updates existing calls from both zoos. You are starting from 2.2, so do not add a separate DisplayTank method.

19.Update DisplayAnimalArea
A Keep its parameters and missing-zoo guard

Remove the common zoo.Pen map lookup. Compare zoo with this.ComoZoo to obtain the pen map and assign penDisplayTextBox.Text. Otherwise compare zoo with this.SanDiegoZoo to obtain the tank map and assign sanDiegoTankDisplayTextBox.Text. Use the diagram’s exact control names.

At the display rename step, the changed method has a blue marker and the replacement AnimalArea suffix is bold blue. The Zoo and string parameters remain unchanged.
MainWindow — rename the display helper
  • New
  • Changed
  • Removed
MainWindow selects the display by comparing zoo references, after handling a missing zoo.
Choose the display by zoo reference
  • New
  • Changed
  • Removed
20.Update CreateSanDiegoZoo
A Replace only the old San Diego pen setup after BirthArea.Mother is assigned

Follow the diagram to allocate the tank, set starting row and column to 1, share FeaturedAnimal, place it, and call DisplayAnimalArea. Keep all earlier setup. Como keeps this.ComoZoo.Pen.PenSpaces = new Animal[4]; and this.ComoZoo.Pen.StartingPosition = 1;, and the renamed display call.

Replace San Diego pen setup with a three-row four-column Tank using the existing featured animal. Every setup assignment uses the SanDiegoZoo instance explicitly.
Replace San Diego’s one-dimensional pen setup
  • New
  • Changed
  • Removed
The three-row four-column array has twelve entries. Only [1,1] holds Patti; Zoo.FeaturedAnimal and Tank.Animal refer to that same object.
Initial tank array and shared mother reference
  • New
  • Changed
  • Removed
TankSpaces immediately after creation — zero-based indexes
0 1 2 3
0 null null null null
1 null Patti null null
2 null null null null
21.Refactor MainWindow’s movement helper
A In MainWindow.xaml.cs, use Ctrl+R, Ctrl+R to rename the existing MoveAnimalInPen helper to MoveFeaturedAnimal

Keep zoo and zooName, but change its final parameter to string direction. Follow the activity diagram to guard a missing zoo, call zoo.MoveFeaturedAnimal(direction), and refresh DisplayAnimalArea. Then compare zoo to this.ComoZoo or this.SanDiegoZoo to display that area’s location and CountAnimals result. Keep the exact messages shown in the diagram. Do not create separate pen and tank movement helpers in MainWindow.

At the MainWindow movement refactor, blue marks the changed helper. MoveFeaturedAnimal and direction string are bold blue; zoo, zooName, and void remain unchanged. Event methods are abbreviated in the methods compartment.
MainWindow — rename the helper and change its direction parameter
  • New
  • Changed
  • Removed
MainWindow.MoveFeaturedAnimal guards zoo creation, delegates movement to Zoo, refreshes the correct map, then displays location and a recalculated count.
MainWindow.MoveFeaturedAnimal — move, refresh, and report
  • New
  • Changed
  • Removed
22.Update all six movement handlers
A Use this complete San Diego up handler as the pattern

Add the down handler and update all four existing left/right handlers using the table. If Visual Studio has already created a handler stub, edit that existing method instead of adding a second method with the same name. Every handler calls MainWindow.MoveFeaturedAnimal with the correct zoo, zooName, and direction string. Use RoutedEventArgs in each signature.

private void moveSanDiegoZooAnimalUpButton_Click(object sender, RoutedEventArgs e)
{
    this.MoveFeaturedAnimal(this.SanDiegoZoo, "San Diego Zoo", "Up");
}
Handler name Helper Zoo zooName direction
moveComoZooAnimalLeftButton_Click MoveFeaturedAnimal this.ComoZoo "Como Zoo" "Left"
moveComoZooAnimalRightButton_Click MoveFeaturedAnimal this.ComoZoo "Como Zoo" "Right"
moveSanDiegoZooAnimalDownButton_Click MoveFeaturedAnimal this.SanDiegoZoo "San Diego Zoo" "Down"
moveSanDiegoZooAnimalLeftButton_Click MoveFeaturedAnimal this.SanDiegoZoo "San Diego Zoo" "Left"
moveSanDiegoZooAnimalRightButton_Click MoveFeaturedAnimal this.SanDiegoZoo "San Diego Zoo" "Right"
23.Include the initial counts
A In the two New Zoo event handlers, keep their setup calls and update the final message statements as shown

Preserve San Diego’s existing temperature update.

// newComoZooButton_Click
this.DisplayMessage("Created " + this.ComoZoo.Name + "." + Environment.NewLine + "Animals in pen: " + this.ComoZoo.CountAnimals() + ".");

// newSanDiegoZooButton_Click
this.DisplayMessage("Created " + this.SanDiegoZoo.Name + "." + Environment.NewLine + "Animals in tank: " + this.SanDiegoZoo.CountAnimals() + ".");
Place each newborn after birth

Keep the existing birth workflow and its returned baby reference. Add the space check before BirthAnimal is called so a blocked birth leaves the unborn baby and the mother unchanged.

24.Update the dingo birth handler
A Follow the activity diagram for this handler

Keep the missing-zoo guard. Check the baby’s destination before calling BirthAnimal, retain the existing failure message, and only place a non-null returned baby. Name it Baby, assign it to the specified array entry, refresh the area, and append CountAnimals to the success message.

The dingo birth handler checks the baby space before birth, places a successful newborn, refreshes the map and appends the zoo count.
Dingo birth handler activity
  • New
  • Changed
  • Removed
25.Update the platypus birth handler
A Follow the activity diagram for this handler

Keep the missing-zoo guard. Check the baby’s destination before calling BirthAnimal, retain the existing failure message, and only place a non-null returned baby. Name it Baby, assign it to the specified array entry, refresh the area, and append CountAnimals to the success message. Preserve the temperature update in the platypus handler.

The platypus birth handler checks the baby space before birth, places a successful newborn, refreshes the map and appends the zoo count.
Platypus birth handler activity
  • New
  • Changed
  • Removed
After birth each area stores two Animal references. The area Animal and zoo FeaturedAnimal references still identify the mother.
Mother and newborn references after successful births
  • New
  • Changed
  • Removed
Check the completed behavior
26.Build before running
A Confirm every XAML Click value has one matching handler

Search for DisplayPen, DisplayTank, and sanDiegoPenDisplayTextBox; the completed code should use DisplayAnimalArea and sanDiegoTankDisplayTextBox instead. Resolve build errors before testing. Search within MainWindow.xaml.cs and MainWindow.xaml, rather than in the diagrams showing the old names. Confirm TankSpaces is allocated before placement, display, search, or movement runs.

Action Expected result
Click any movement arrow before creating its zoo Create-zoo message; no exception
Create both zoos Como: - X - -; San Diego: three rows with X at [1, 1]; each creation message reports 1
Birth both babies without moving the mothers Como: x X - -; San Diego: x at [0, 0] and X at [1, 1]; each success reports 2
Move Como left after birth Array and map stay x X - -; count remains 2
Move Como right twice, then right again Mother reaches index 3; the extra move is blocked; baby stays at index 0
Click New San Diego Zoo, move up and left once each, then click Birth platypus Mother occupies [0, 0]; birth is blocked before reproduction
Move that mother right, then birth Baby occupies [0, 0]; mother stays [0, 1]; count becomes 2
Click San Diego left now Baby blocks the destination; both references and count are unchanged
Move to each tank boundary and attempt to cross it No invalid index access; mother stays in bounds
Create one zoo again Its map resets to one mother and the creation message reports 1; the other zoo is unchanged
27.Check earlier features
A Feed both mothers, refill both vending machines, and adjust the birthing-room temperature

Confirm earlier behavior is preserved. Try an unsupported direction in a temporary edit: the area should return without moving; restore the handler afterward. No averages or species-letter markers are required.

Step into the tank and watch the references

Use F11 (Step Into), Watch, and Autos to follow a San Diego right-arrow click. A highlighted statement normally has not executed yet. Use F11 through method calls and returns; no Immediate Window commands are needed.

28.Pause in the right-arrow handler
A Create both zoos without giving birth

Click New San Diego Zoo again if you previously moved Patti or gave birth; the upcoming tables assume a fresh tank with only Patti at [1, 1]. Set a breakpoint on the MoveFeaturedAnimal call inside moveSanDiegoZooAnimalRightButton_Click, then click that arrow. Open Debug > Windows > Watch > Watch 1 and add the expressions in the table before stepping into the helper.

Expression In the button handler Inside MainWindow.MoveFeaturedAnimal
this.SanDiegoZoo.Tank.TankSpaces 3 rows × 4 columns; Patti at [1, 1] Same array
zoo.Name Unavailable in this scope "San Diego Zoo"
direction Unavailable in this scope "Right"
29.Follow the direction through Zoo and Tank
A Use F11 to enter MainWindow.MoveFeaturedAnimal, then step into zoo.MoveFeaturedAnimal(direction)
Follow the direction through Zoo and Tank
Current method this refers to Watch expressions and expected values Next F11 action
Zoo.MoveFeaturedAnimal The San Diego Zoo object this.Pen: null
this.Tank: the tank reference
direction: "Right"
Step into this.Tank.MoveAnimal(direction).
Tank.MoveAnimal The tank object direction is "Right"; rowChange and columnChange are unavailable because they are parameters of MoveAnimalInTank Follow the "Right" case and step into this.MoveAnimalInTank(0, 1).
Tank.MoveAnimalInTank The same tank object rowChange is 0; columnChange is 1; direction is unavailable because it belongs to the calling method Continue into the coordinate searches.
30.Step into the coordinate searches
A Inside Tank.MoveAnimalInTank, add this.TankSpaces, this.Animal.Name, row, column, newRow, and newColumn to Watch

Use F11 to follow the searches. Observe each expected value after the indicated statement executes. In each Watch-expression cell, add each displayed line as a separate Watch entry; the expected values appear in the same order.

Trace the coordinate searches
Current method Pause after Watch expression Expected value or observation
Tank.FindAnimalRow The result initializer foundRow -1
Tank.FindAnimalRow The loop initializers row
column
0
0; row 0 has no mother reference.
Tank.FindAnimalRow The matching assignment row
column
foundRow
1
1
1
Tank.FindAnimalRow The matching assignment this.TankSpaces[row, column] The same Patti reference held by this.Animal.
Tank.MoveAnimalInTank FindAnimalRow returns and its assignment executes row 1
Tank.FindAnimalColumn The result initializer foundColumn -1
Tank.FindAnimalColumn The matching assignment row
column
foundColumn
1
1
1
Tank.MoveAnimalInTank FindAnimalColumn returns and its assignment executes column 1

The search loop variables and the movement helper’s locals belong to different methods. Follow both breaks in each search before returning to the movement helper.

31.Observe the destination and assignments
A In Tank.MoveAnimalInTank, row and column receive 1 and 1

Use F11 to inspect the destination and follow the two array assignments.

Observe the destination and array changes
Current method Pause after Watch expression Expected value or observation
Tank.MoveAnimalInTank The newRow assignment newRow 1
Tank.MoveAnimalInTank The newColumn assignment newColumn 2
Tank.IsValidLocation Entering the method row
column
1
2
Tank.MoveAnimalInTank The validity call returns this.TankSpaces[newRow, newColumn] null; the destination is empty.
Tank.MoveAnimalInTank The old-entry assignment this.TankSpaces[1, 1] null
Tank.MoveAnimalInTank The old-entry assignment this.Animal.Name "Patti"; clearing the entry has not lost the mother reference.
Tank.MoveAnimalInTank The destination assignment this.TankSpaces[1, 2] Patti

The window map still shows its previous value. It refreshes after movement returns to MainWindow.

32.Follow returns to the map and message refresh
A Use F11 through the returns from Tank.MoveAnimalInTank, Tank.MoveAnimal, and Zoo.MoveFeaturedAnimal until MainWindow resumes

Continue with F11 through the map refresh, location description, and count.

Follow the display and message values
Current method F11 action or statement to execute Watch expression Expected value or observation
MainWindow.DisplayAnimalArea Pause before entering GetDisplayLocation. this.sanDiegoTankDisplayTextBox.Text Still shows the previous map. While inside Tank, this window expression is unavailable.
MainWindow.DisplayAnimalArea Execute the Text assignment. this.sanDiegoTankDisplayTextBox.Text Three rows; the mother marker is now at row index 1, column index 2.
Tank.ContainsAnimal Follow the foreach called by GetAnimalLocation. tankAnimal
containsAnimal
Patti when the matching entry is reached.
true after the assignment; break then ends the search.
Tank.GetAnimalLocation Follow both coordinate searches and the display-coordinate assignments. row
column
displayRow
displayColumn
1
2
2
3
Tank.GetAnimalLocation Execute the description assignment. location "Patti is in tank row 2, column 3."
Zoo.CountAnimals Follow the area checks. this.Pen
this.Tank
null
The San Diego tank reference.
Zoo.CountAnimals Follow the foreach and matching increment. animal
count
Patti at the occupied entry.
1 after incrementing for Patti.
MainWindow.DisplayMessage Execute the Text assignment. this.informationTextBox.Text "Patti is in tank row 2, column 3."
"Animals in tank: 1."
A fresh San Diego Zoo right-arrow example shows the nested MainWindow, Zoo, and Tank calls and balanced returns. Array updates precede map refresh, membership checking, and the count message.
Arrow click, movement, display refresh, membership search, and count
  • New
  • Changed
  • Removed
33.Watch a blocked move after birth
A Click New San Diego Zoo, click Birth platypus, and move up once so Patti is at [0, 1]

Break on the left-arrow attempt. Use F11 to follow MainWindow, Zoo, and Tank.MoveAnimal into Tank.MoveAnimalInTank(0, -1).

Inspect a move blocked by the baby
Current method Watch expression or condition Expected value or observation
Tank.MoveAnimalInTank rowChange
columnChange
0
-1
Tank.MoveAnimalInTank row
column
0
1, after the search assignments execute.
Tank.MoveAnimalInTank newRow
newColumn
0
0, after the destination assignments execute.
Tank.MoveAnimalInTank this.IsValidLocation(newRow, newColumn) true; the baby’s position is inside the tank.
Tank.MoveAnimalInTank this.TankSpaces[newRow, newColumn] The Baby reference.
Tank.MoveAnimalInTank this.TankSpaces[newRow, newColumn] == null false; neither movement assignment runs.
MainWindow.DisplayAnimalArea this.sanDiegoTankDisplayTextBox.Text The baby remains x at [0, 0]; Patti remains X at [0, 1].
Zoo.CountAnimals count 2 before returning.

Remove breakpoints after the check.

Review the completed class structure

Compare your finished classes with the diagram. Green identifies new members, blue identifies changed members, and red identifies renamed old members.

Green marks new members, blue marks changed members, red marks the renamed old method. Tank is new; event methods remain abbreviated in the methods compartment.
Ending class structure — green: new; blue: changed; red: renamed old member
  • New
  • Changed
  • Removed
Submit Zoo 2.3
34.Save and submit your project
A Remove temporary experiments

Confirm Como uses four pen spaces, San Diego uses three tank rows and four columns, both babies remain fixed, and the count changes only when occupancy changes. Submit the completed Zoo 2.3 project using your course procedure.