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.
Fields describe an object's state. Methods describe what an object can do.
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.
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.
This checkpoint adds behavior without introducing later-course concepts. The custom methods added here remain parameterless and return void.
Wallet.Wallet.RemoveMoney() subtracts the fixed $$2.00 feeding amount.VendingMachine.AddMoney() adds $$2.00.VendingMachine.SellFood() calls AddMoney() and subtracts 1.0 from FoodStock.Animal.Eat() changes the animal's weight using the current endpoint calculation.RemoveMoney() → SellFood() → Eat() in that order.VendingMachine.AddFoodBag() increases stock by the current BagSize.Animal.MakePregnant() changes pregnancy state and Animal.Move() represents movement behavior.CreateComoZoo() and CreateSanDiegoZoo() organize the two creation flows.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;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.
}C#
public Guest Visitor;| Value | Como Zoo | San Diego Zoo |
|---|---|---|
| Guest | Darla | Dave |
| Age | 11 | 13 |
| PortionSize | 1.0 | 1.0 |
| Wallet balance | 5.25m | 3.75m |
ComoZoo.Visitor.Name = "Darla" and ComoZoo.Visitor.Wallet.MoneyBalance = 5.25mSanDiegoZoo.Visitor.Name = "Dave" and SanDiegoZoo.Visitor.Wallet.MoneyBalance = 3.75mC#
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.
RemoveMoney() belongs to Wallet2.0m and does not return a valueC#
public void AddMoney()
{
this.MoneyBalance += 2.0m;
}MoneyBalancevoidC#
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.
SellFood() calls AddMoney()2.0m to money and removes 1.0 pound of foodC#
public double EatWeightGainPercentage = 0.8;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.
35.3 to 63.54 after one call3.27 to 5.886 after one callXAML
<Button x:Name="darlaFeedDingoButton" Content="Darla, feed dingo" Click="darlaFeedDingoButton_Click"/>
C#
public void darlaFeedDingoButton_Click(object sender, RoutedEventArgs e)
{
this.ComoZoo.Visitor.Wallet.RemoveMoney();
this.ComoZoo.AnimalSnackMachine.SellFood();
this.ComoZoo.FeaturedAnimal.Eat();
}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.
5.25 → → 3.250 → → 2.000 → → -1.035.3 → → 63.54XAML
<Button x:Name="daveFeedPlatypusButton" Content="Dave, feed platypus" Click="daveFeedPlatypusButton_Click"/>
C#
public void daveFeedPlatypusButton_Click(object sender, RoutedEventArgs e)
{
this.SanDiegoZoo.Visitor.Wallet.RemoveMoney();
this.SanDiegoZoo.AnimalSnackMachine.SellFood();
this.SanDiegoZoo.FeaturedAnimal.Eat();
}3.75 → → 1.750 → → 2.000 → → -1.03.27 → → 5.886Set a breakpoint on:
C#
this.ComoZoo.Visitor.Wallet.RemoveMoney();VendingMachine.AddMoney()
VendingMachine.SellFood()
MainWindow.darlaFeedDingoButton_Click(...)SellFood() → → AddMoney() path in the Call Stack.C#
public void AddFoodBag()
{
this.FoodStock += this.BagSize;
}BagSize = 65 and FoodStock = 0, one call produces 65.130.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();
}FoodStock = 0, click the refill button once, and confirm FoodStock = 65XAML
<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();
}FoodStock = 0, click the refill button once, and confirm FoodStock = 653.25.MoneyBalance = 2.00.FoodStock = 64.0.Weight = 63.54.C#
public void MakePregnant()
{
this.IsPregnant = true;
}IsPregnant field to trueC#
public void Move()
{
}voidC#
this.ComoZoo.FeaturedAnimal.MakePregnant();C#
this.SanDiegoZoo.FeaturedAnimal.MakePregnant();IsPregnant = trueC#
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.
| Area | Current state |
|---|---|
| Zoo | Name = "Como Zoo", Capacity = 1000 |
| Ticket booth | TicketPrice = 15.00m, attendant Sam, number 42 |
| Visitor | Darla, age 11, wallet 5.25m, portion size 1.0 |
| Vending machine | BagSize = 65.0, FoodCapacity = 250.0, FoodPricePerPound = 0.75m |
| Birthing room | InitialTemperature = 77.0, max 85.0, min 55.0, increase 0.5, current temperature = initial temperature |
| Doctor | Flora, number 98 |
| Restrooms | Ladies: capacity 4, Female; Mens: capacity 4, Male |
| Featured animal | Dolly, Female, age 4, weight 35.3, happiness 0, type Dingo, pregnancy through MakePregnant() |
InitialTemperature = 77.0FoodStock and MoneyBalance begin at their default numeric value 0MakePregnant()C#
public void newComoZooButton_Click(object sender, RoutedEventArgs e)
{
this.CreateComoZoo();
}C#
public void CreateSanDiegoZoo()| Area | Current state |
|---|---|
| Zoo | Name = "San Diego Zoo", Capacity = 3000 |
| Ticket booth | TicketPrice = 25.50m, attendant Betty, number 84 |
| Visitor | Dave, age 13, wallet 3.75m, portion size 1.0 |
| Vending machine | BagSize = 65.0, FoodCapacity = 250.0, FoodPricePerPound = 1.20m |
| Birthing room | InitialTemperature = 77.0, max 85.0, min 55.0, increase 0.5, current temperature = initial temperature |
| Doctor | Steve, number 24 |
| Restrooms | Ladies: capacity 12, Female; Mens: capacity 12, Male |
| Featured animal | Patti, Female, age 5, weight 3.27, happiness 0, type Platypus, pregnancy through MakePregnant() |
InitialTemperature = 77.0MakePregnant()C#
public void newSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
{
this.CreateSanDiegoZoo();
}Set a breakpoint on:
C#
this.CreateComoZoo();Code
Animal.MakePregnant()
MainWindow.CreateComoZoo()
MainWindow.newComoZooButton_Click(...)Submit the completed Zoo 1.3 project according to your instructor's directions.
Code
Wallet.RemoveMoney()
VendingMachine.SellFood()
→ VendingMachine.AddMoney()
Animal.Eat()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.