1.3 Zoo Instruction

Overview

Methods

Zoo 1.3 shifts from objects that mainly store state to objects that also perform behavior. You will add parameterless void methods to the existing zoo model, connect those methods to UI actions, and trace execution as methods call other methods.

Central idea

Fields describe an object's state. Methods describe what an object can do.

Getting Started

Keep a working copy

Keep your Zoo 1.2 checkpoint unchanged. If a later change causes a problem, the previous working checkpoint gives you a known-good source to compare against.

Starting Point — End of Zoo 1.2

Zoo 1.3 begins with the two-zoo object model already established. The existing project includes the current Zoo, Animal, Employee, Restroom, Booth, BirthingRoom, and VendingMachine classes, plus the Como and San Diego object graphs.

Zoo 1.2 starting class structure for Zoo 1.3. MainWindow references ComoZoo and SanDiegoZoo. Each Zoo references its existing featured animal, restrooms, ticket booth, birthing room, and vending machine. No Zoo 1.3 additions are marked.
Starting structure: authoritative end-of-Zoo-1.2 context.

This checkpoint adds behavior without introducing later-course concepts. The custom methods added here remain parameterless and return void.

Acceptance Criteria

User Story 1 — Complete a guest feeding transaction

The zoo now needs a guest action that affects several connected objects instead of changing one field directly.

As a zoo guest, I want to purchase food and feed the zoo's featured animal so that my money, the vending machine, and the animal all reflect the action I performed.

Task 1 — Give each zoo guest a wallet

Problem

The existing zoo model does not yet give the visitor an object that owns the guest's money.

Solution

Add the current Guest and Wallet classes, connect Guest to Wallet, and connect each zoo to its current visitor.

Step 1 — Add Wallet

Add Wallet.cs to the existing Business Classes folder. Keep the current project namespace, XML documentation style, and StyleCop suppression pattern.

C#

public decimal MoneyBalance;

Step 2 — Add Guest

C#

public double PortionSize;
public int Age;
public string Name;
public Wallet Wallet;

C#

public void Eat()
{
    // No state change is needed for this example.
}

Step 3 — Connect the visitor to Zoo

C#

public Guest Visitor;
Progressive Zoo 1.3 class diagram. Green squares mark the new Guest and Wallet classes, their current fields and Guest Eat method, Zoo Visitor relationship, and Guest Wallet relationship.
Add Guest and Wallet and connect them to Zoo.

Step 4 — Create the current visitors and wallets

ValueComo ZooSan Diego Zoo
GuestDarlaDave
Age1113
PortionSize1.01.0
Wallet balance5.25m3.75m

Check Your Work

Go to top

Task 2 — Pay for one feeding transaction

Problem

The guest's wallet contains money, but no wallet-owned behavior changes that balance yet.

Solution

Add a focused RemoveMoney() method that subtracts the fixed Zoo 1.3 transaction amount.

Step 1 — Add RemoveMoney()

Progressive Wallet class diagram. A green square marks the new RemoveMoney method; MoneyBalance is existing context from the current task.
Add the focused RemoveMoney behavior to Wallet.

C#

public void RemoveMoney()
{
    this.MoneyBalance -= 2.0m;
}

The m suffix makes 2.0m a decimal. If the balance starts at 5.25m, one call produces 3.25m.

Check Your Work

Go to top

Task 3 — Record money received by the vending machine

Problem

The vending machine can store a money balance, but it has no method that records the fixed payment for one sale.

Solution

Add a focused AddMoney() method to the vending machine.

Step 1 — Add AddMoney()

Progressive VendingMachine class diagram. A green square marks the new AddMoney method; existing vending-machine fields are unmarked.
Add AddMoney to VendingMachine.

C#

public void AddMoney()
{
    this.MoneyBalance += 2.0m;
}

Check Your Work

Go to top

Task 4 — Sell one pound of animal food

Problem

A sale changes two pieces of vending-machine state: money enters the machine and food leaves the machine.

Solution

Add SellFood() so it calls the existing AddMoney() method and then reduces food stock.

Step 1 — Add SellFood()

Progressive VendingMachine class diagram. A green square marks the new SellFood method; AddMoney and the current state fields remain unmarked context.
SellFood becomes a second focused vending-machine behavior.
Sequence diagram for one vending-machine sale. A green square marks the SellFood call. SellFood calls AddMoney on the same vending-machine object, then the machine reduces FoodStock.
SellFood calls another method on the same object before updating food stock.

C#

public void SellFood()
{
    this.AddMoney();
    this.FoodStock -= 1.0;
}

this.AddMoney() calls another method on the same VendingMachine object. When that call returns, execution continues with the FoodStock subtraction.

Check Your Work

Go to top

Task 5 — Let the featured animal eat

Problem

The feeding action needs to change animal weight, but the calculation should not live in the UI layer.

Solution

Give Animal a focused Eat() behavior that updates the current animal's own weight.

Step 1 — Add the current weight-gain percentage

C#

public double EatWeightGainPercentage = 0.8;

Step 2 — Add Eat()

Progressive Animal class diagram. Green squares mark the new EatWeightGainPercentage field and Eat method; existing Animal state remains unmarked context.
Animal gains its first current feeding behavior.

C#

public void Eat()
{
    this.Weight = this.Weight + (this.Weight * this.EatWeightGainPercentage);
}

For Dolly: 35.3 + (35.3 × 0.8) = 63.54.

For Patti: 3.27 + (3.27 × 0.8) = 5.886.

Check Your Work

Go to top

Task 6 — Connect the Como Zoo feeding action

Problem

The Como feed button must coordinate three separate objects without duplicating the state-change logic in MainWindow.

Solution

Call the wallet, vending-machine, and animal methods in the approved transaction order.

Step 1 — Confirm the button

XAML

<Button x:Name="darlaFeedDingoButton" Content="Darla, feed dingo" Click="darlaFeedDingoButton_Click"/>

Step 2 — Complete the event handler

C#

public void darlaFeedDingoButton_Click(object sender, RoutedEventArgs e)
{
    this.ComoZoo.Visitor.Wallet.RemoveMoney();
    this.ComoZoo.AnimalSnackMachine.SellFood();
    this.ComoZoo.FeaturedAnimal.Eat();
}
Sequence diagram for the Como feeding transaction. Green squares mark the UI-requested calls RemoveMoney, SellFood, and Eat. SellFood makes the nested AddMoney call on the same vending-machine object.
Como feed flow: wallet payment → vending-machine sale → animal eating.
There is no inventory decision yet

If FoodStock is 0, one sale produces -1.0. Do not add an if statement in Zoo 1.3; decision logic belongs to a later checkpoint.

Check Your Work

Go to top

Task 7 — Connect the San Diego Zoo feeding action

Problem

The same behaviors must work for a second zoo without creating duplicate domain methods.

Solution

Call the same Wallet, VendingMachine, and Animal methods through the San Diego object graph.

Step 1 — Confirm the button

XAML

<Button x:Name="daveFeedPlatypusButton" Content="Dave, feed platypus" Click="daveFeedPlatypusButton_Click"/>

Step 2 — Complete the event handler

C#

public void daveFeedPlatypusButton_Click(object sender, RoutedEventArgs e)
{
    this.SanDiegoZoo.Visitor.Wallet.RemoveMoney();
    this.SanDiegoZoo.AnimalSnackMachine.SellFood();
    this.SanDiegoZoo.FeaturedAnimal.Eat();
}

Check Your Work

Go to top

Task 8 — Trace the feeding transaction

Problem

The transaction now crosses several methods, so Step Over alone does not show how control moves between callers and called methods.

Solution

Use Step Into, Step Out, Continue, and the Call Stack to trace the complete Como feeding path.

Step 1 — Trace the wallet call

Method-call trace map for the Como feeding transaction. MainWindow calls Wallet.RemoveMoney, VendingMachine.SellFood, and Animal.Eat; SellFood calls AddMoney on the same vending machine.
Use this sequence as the map for the debugger trace.

Set a breakpoint on:

C#

this.ComoZoo.Visitor.Wallet.RemoveMoney();

Step 2 — Trace the nested vending-machine call

Code

VendingMachine.AddMoney()
VendingMachine.SellFood()
MainWindow.darlaFeedDingoButton_Click(...)

Step 3 — Trace the animal call

Check Your Work

Go to top

User Story 2 — Keep animal-food vending machines stocked

As a zoo employee, I want to add food bags to the animal-food vending machine so that food is available for guest feeding transactions.

Task 1 — Add a food bag to a vending machine

Problem

The machine stores both its current food stock and bag size, but no behavior connects those two pieces of state.

Solution

Add AddFoodBag() so the vending machine updates its own stock.

Step 1 — Add AddFoodBag()

Progressive VendingMachine class diagram. A green square marks the new AddFoodBag method; AddMoney and SellFood are existing Zoo 1.3 context.
Add the vending-machine refill behavior.

C#

public void AddFoodBag()
{
    this.FoodStock += this.BagSize;
}

Check Your Work

Go to top

Task 2 — Refill the Como Zoo vending machine

Problem

Como Zoo needs a UI action that requests the vending-machine refill behavior.

Solution

Connect Flora's refill button to AddFoodBag() on the Como vending machine.

Step 1 — Confirm the button and handler

Sequence diagram for the refill action. A green square marks MainWindow calling AddFoodBag on the current VendingMachine, which updates FoodStock from its current value using BagSize.
The UI requests the refill; the vending machine owns the stock calculation.

XAML

<Button x:Name="floraFillVendingMachineButton" Content="Flora, fill vending machine" Click="floraFillVendingMachineButton_Click"/>

C#

public void floraFillVendingMachineButton_Click(object sender, RoutedEventArgs e)
{
    this.ComoZoo.AnimalSnackMachine.AddFoodBag();
}

Check Your Work

Go to top

Task 3 — Refill the San Diego Zoo vending machine

Problem

San Diego Zoo needs the same refill behavior on its own machine.

Solution

Connect Betty's refill button to the same AddFoodBag() method through the San Diego object graph.

Step 1 — Confirm the button and handler

XAML

<Button x:Name="bettyFillVendingMachineButton" Content="Betty, fill vending machine" Click="bettyFillVendingMachineButton_Click"/>

C#

public void bettyFillVendingMachineButton_Click(object sender, RoutedEventArgs e)
{
    this.SanDiegoZoo.AnimalSnackMachine.AddFoodBag();
}

Check Your Work

Go to top

Task 4 — Verify repeated refills

Problem

A state-changing method should work from the object's current value, not only from its original starting value.

Solution

Call AddFoodBag() more than once and verify that each call adds one current bag size.

Step 1 — Refill more than once

Step 2 — Combine refill and feed

Check Your Work

Go to top

User Story 3 — Let zoo objects perform focused behaviors

As a zoo employee, I want animal state changes to occur through meaningful animal behaviors so that the object responsible for the state also controls the action that changes it.

Task 1 — Change pregnancy state through behavior

Problem

The featured animal has pregnancy state, but the state change should belong to the animal rather than MainWindow.

Solution

Add a focused MakePregnant() method to Animal.

Step 1 — Add MakePregnant()

Progressive Animal class diagram. A green square marks the new MakePregnant method; current weight and feeding behavior remain unmarked context.
Add pregnancy-state behavior to Animal.

C#

public void MakePregnant()
{
    this.IsPregnant = true;
}

Check Your Work

Go to top

Task 2 — Represent animal movement as behavior

Problem

Movement belongs to an animal, but this checkpoint does not yet require additional movement state or parameters.

Solution

Add the current empty Move() method so movement is represented as an animal-owned behavior.

Step 1 — Add Move()

Progressive Animal class diagram. A green square marks the new Move method; Eat and MakePregnant are existing Zoo 1.3 behavior.
Add movement as an Animal-owned behavior.

C#

public void Move()
{
}

Check Your Work

Go to top

Task 3 — Use MakePregnant() when creating the featured animals

Problem

A focused animal behavior now exists, so MainWindow should request that behavior instead of directly assigning pregnancy state.

Solution

Call MakePregnant() on each featured animal after its current fields are established.

Step 1 — Call the behavior for Dolly

Sequence diagram showing MainWindow's zoo-creation method calling MakePregnant on the current featured Animal. A green square marks the CreateComoZoo call in this focused diagram.
The creation method requests the animal's pregnancy-state behavior.

C#

this.ComoZoo.FeaturedAnimal.MakePregnant();

Step 2 — Call the behavior for Patti

C#

this.SanDiegoZoo.FeaturedAnimal.MakePregnant();

Check Your Work

Go to top

User Story 4 — Organize zoo creation into focused application actions

The New Zoo buttons currently represent large setup actions that are easier to trace when the detailed work is moved into focused methods.

As a user of the zoo application, I want each zoo to be created through one clear action so that all of the objects needed for that zoo are prepared together when I choose to create it.

Task 1 — Create the Como Zoo through a focused method

Problem

The New Como Zoo event handler should not own every detail of the object-creation flow.

Solution

Move the working Como setup statements into CreateComoZoo() while preserving the current object graph and values.

Step 1 — Add the creation method

Progressive class diagram. Green squares mark the new MainWindow CreateComoZoo and CreateSanDiegoZoo methods. Existing Zoo and FeaturedAnimal relationships provide context.
Move the two large setup flows into focused MainWindow methods.

C#

public void CreateComoZoo()

Move the existing Como creation statements into this method. Do not rewrite the entire object graph from memory; preserve the current working relationships and values.

AreaCurrent state
ZooName = "Como Zoo", Capacity = 1000
Ticket boothTicketPrice = 15.00m, attendant Sam, number 42
VisitorDarla, age 11, wallet 5.25m, portion size 1.0
Vending machineBagSize = 65.0, FoodCapacity = 250.0, FoodPricePerPound = 0.75m
Birthing roomInitialTemperature = 77.0, max 85.0, min 55.0, increase 0.5, current temperature = initial temperature
DoctorFlora, number 98
RestroomsLadies: capacity 4, Female; Mens: capacity 4, Male
Featured animalDolly, Female, age 4, weight 35.3, happiness 0, type Dingo, pregnancy through MakePregnant()

Check Your Work

Go to top

Task 2 — Connect the New Como Zoo control

Problem

The button event should respond to the UI event without containing the complete setup algorithm.

Solution

Have the event handler call CreateComoZoo().

Step 1 — Simplify the event handler

C#

public void newComoZooButton_Click(object sender, RoutedEventArgs e)
{
    this.CreateComoZoo();
}

Check Your Work

Go to top

Task 3 — Create the San Diego Zoo through a focused method

Problem

The San Diego creation flow should use the same organization as Como while preserving its separate state.

Solution

Move the current San Diego setup statements into CreateSanDiegoZoo().

Step 1 — Add the creation method

C#

public void CreateSanDiegoZoo()
AreaCurrent state
ZooName = "San Diego Zoo", Capacity = 3000
Ticket boothTicketPrice = 25.50m, attendant Betty, number 84
VisitorDave, age 13, wallet 3.75m, portion size 1.0
Vending machineBagSize = 65.0, FoodCapacity = 250.0, FoodPricePerPound = 1.20m
Birthing roomInitialTemperature = 77.0, max 85.0, min 55.0, increase 0.5, current temperature = initial temperature
DoctorSteve, number 24
RestroomsLadies: capacity 12, Female; Mens: capacity 12, Male
Featured animalPatti, Female, age 5, weight 3.27, happiness 0, type Platypus, pregnancy through MakePregnant()

Check Your Work

Go to top

Task 4 — Connect the New San Diego Zoo control

Problem

The New San Diego Zoo event handler should request the larger creation action instead of containing every setup statement.

Solution

Have the event handler call CreateSanDiegoZoo().

Step 1 — Simplify the event handler

C#

public void newSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
{
    this.CreateSanDiegoZoo();
}

Check Your Work

Go to top

Task 5 — Trace a method called from another method

Problem

Zoo creation now contains a method call inside another method, which gives you a second nested call path to inspect.

Solution

Trace the New Como Zoo event into CreateComoZoo() and then into Animal.MakePregnant().

Step 1 — Enter the creation method

Method-call trace map for zoo creation. The New Como Zoo event enters MainWindow.CreateComoZoo, which calls Animal.MakePregnant on the featured animal.
Use this sequence as the map for the zoo-creation debugger trace.

Set a breakpoint on:

C#

this.CreateComoZoo();

Step 2 — Enter the animal method

Code

Animal.MakePregnant()
MainWindow.CreateComoZoo()
MainWindow.newComoZooButton_Click(...)

Check Your Work

Go to top

Finish and Submit

Final Como transaction check

Final San Diego transaction check

Debugger check

Submit Your Work

Submit the completed Zoo 1.3 project according to your instructor's directions.

Go to top

Checkpoint Summary

Zoo 1.3 adds focused behavior to the object model.

Final Zoo 1.3 class diagram. Green squares mark all new Zoo 1.3 structural items: Guest, Wallet, Zoo Visitor and Guest Wallet relationships; Wallet RemoveMoney; Animal EatWeightGainPercentage, Eat, MakePregnant, and Move; VendingMachine AddFoodBag, AddMoney, and SellFood; and MainWindow CreateComoZoo and CreateSanDiegoZoo. Existing Zoo 1.2 context is unmarked. There are no Changed or Removed structural items.
Final structural delta: New items only; Changed none; Removed none.

Feeding transaction

Code

Wallet.RemoveMoney()
VendingMachine.SellFood()
    → VendingMachine.AddMoney()
Animal.Eat()

Other current behaviors

Code

VendingMachine.AddFoodBag()
Animal.MakePregnant()
Animal.Move()
MainWindow.CreateComoZoo()
MainWindow.CreateSanDiegoZoo()

All custom methods introduced at this checkpoint remain parameterless void methods. Parameters, returned values, and decision logic are reserved for later checkpoints.