1.2 Zoo Learning Activity

Zoo Instruction
1.Overview
A Classes and Reusable Object Blueprints

Zoo 1.2 shifts from working mainly with individual objects to defining the class blueprints those objects use. You will add BirthingRoom and VendingMachine, create Como Zoo objects from those definitions, and reuse the same class design for a separate San Diego Zoo.

A class defines a reusable kind of object. Multiple objects can be created from the same class, and each object can maintain its own state.

B Getting Started
C Make a copy of the Zoo 1.1 [LastName] folder
D Rename the copied folder to Zoo 1.2 [LastName]
E Rename Zoo 1.1 [LastName].sln to Zoo 1.2 [LastName].sln
F Open the copied Zoo 1.2 solution

Make a copy of your code at the beginning of each week and rename the folder and ..sln file to the appropriate week number. Doing so will help you maintain a record of your work and keep a working copy of your code in case you need to revert your changes.

G Starting Point — End of Zoo 1.1

This class structure already exists. Zoo 1.2 extends it.

Zoo 1.1 starting class diagram. MainWindow references Zoo through ComoZoo. Zoo references Animal through FeaturedAnimal, Restroom through LadiesRoom and MensRoom, and Booth through TicketBooth. Booth references Employee through Attendant. Existing scalar members are shown in their owning classes.
Authoritative Zoo 1.1 End class structure.
  • New
  • Changed
  • Removed
H Acceptance Criteria
  • BirthingRoom and VendingMachine use only the current Zoo 1.2 fields.
  • Zoo contains BirthArea : BirthingRoom and AnimalSnackMachine : VendingMachine.
  • Como Zoo has its own configured birthing-room and vending-machine objects.
  • BirthArea.Doctor refers to Flora, number 98.
  • MainWindow contains SanDiegoZoo : Zoo.
  • San Diego Zoo reuses the same class definitions while maintaining separate object state.
  • No later-course design techniques are added.
Use a birthing room for animal care
2.Add the birthing room to the zoo model

Define BirthingRoom and add only the current Zoo 1.2 fields and class relationships required by the scenario.

A Add the BirthingRoom class

Before you write the new class, use Solution Explorer to add the class file to the ZooScenario project.

B Add a class through Solution Explorer
C In Solution Explorer, right-click the ZooScenario project node
D Choose Add
E Choose Class...
F In the Add New Item workflow, create the file as BirthingRoom.cs
Visual Studio Solution Explorer showing the ZooScenario project context menu with Add expanded and Class visible.
Right-click the ZooScenario project, choose Add , then choose Class... .

Now continue with the class structure for BirthingRoom.

Progressive class diagram. A green square marks BirthingRoom as the new class. Existing Zoo, Animal, and Employee classes provide context.
Add the BirthingRoom class.
  • New
  • Changed
  • Removed
G Move the BirthingRoom class into the Business Classes folder

Insert the following suppression pattern. Keep the two attributes together in one horizontally scrollable code frame and keep each attribute on one physical source line:

C#

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Event handlers may begin with lower-case letters.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
H Add the temperature fields

BirthingRoom exists, but it does not yet describe the temperature information the current scenario needs.

Add the five current scalar fields shown in the class diagram.

Progressive BirthingRoom class diagram. Green squares mark the new fields InitialTemperature double, MaxTemperature double, MinTemperature double, TemperatureIncrease double, and Temperature double.
The five current temperature fields belong inside BirthingRoom.
  • New
  • Changed
  • Removed

These values belong to one birthing-room object's state. double supports the current fractional values such as 77.0 and 0.5.

I Add the five fields shown by the diagram
J Add comments to the class and each field, following the comment style already used in the project
K Check Your Work
1 Build
2 Confirm all five members use the names and types shown by the diagram
L Add the Animal relationship

A birthing-room object must be able to refer to an animal when the scenario requires one.

Add the current Animal-typed field represented as a class relationship.

Progressive class diagram showing BirthingRoom related to Animal. A green square marks the new relationship role Animal.
BirthingRoom can reference an Animal object through the Animal role.
  • New
  • Changed
  • Removed

Animal is the class/type and also the field/role name. The class relationship describes what a BirthingRoom can reference; it does not create an Animal object.

M Add the documented current class-typed field represented by the diagram
N Check Your Work
1 Build
2 Confirm the field uses the existing Animal class and exact current field name
O Add the Doctor relationship

The room also needs a reference to the employee serving as the doctor.

Add the current Employee-typed Doctor field.

Progressive class diagram showing BirthingRoom related to Employee. A green square marks the new Doctor relationship. The established Animal relationship remains unmarked.
Doctor is an Employee role, not a separate Doctor class.
  • New
  • Changed
  • Removed
P Add the documented current Doctor field represented by the diagram
Q Check Your Work
1 Build
2 Confirm no separate Doctor class was introduced
3.Set up the Como Zoo birthing room

Connect Zoo to BirthingRoom, then create and configure the Como BirthArea.

A Add BirthArea to Zoo
Progressive class diagram showing a green square on the new BirthArea relationship from Zoo to BirthingRoom. BirthingRoom already has its temperature fields and Animal and Doctor relationships.
Zoo can reference its own BirthingRoom through BirthArea.
  • New
  • Changed
  • Removed

Declaring BirthArea creates the class relationship. It does not create the runtime BirthingRoom object.

B Add the documented BirthArea field to Zoo
C Check Your Work
1 Build
2 Confirm the new relationship compiles and the existing Zoo 1.1 members remain intact
D Create and configure the Como BirthArea
E Create a BirthingRoom object in the existing Como Zoo creation flow and store it in ComoZoo.BirthArea
F Set InitialTemperature = 77.0, MaxTemperature = 85.0, MinTemperature = 55.0, TemperatureIncrease = 0.5, and Temperature = 77.0
G Create/connect the current doctor Employee: Name = "Flora", Number = 98, and BirthArea.Doctor → Flora

This focused source line adds separate meaning because it shows that the current temperature is initialized from the initial temperature:

C#

this.ComoZoo.BirthArea.Temperature = this.ComoZoo.BirthArea.InitialTemperature;
Completed Como BirthArea object diagram. Green squares mark the new BirthArea object and reference, the assigned values InitialTemperature 77.0, MaxTemperature 85.0, MinTemperature 55.0, TemperatureIncrease 0.5, and Temperature 77.0, plus the new Flora Employee object with Name Flora and Number 98 and the Doctor reference from BirthArea to Flora. Untouched default or uninitialized members are omitted.
Completed Como BirthArea state. Only intentionally established current state is shown.
  • New
  • Changed
  • Removed
H Check Your Work
1 Inspect ComoZoo.BirthArea
2 Confirm all five numeric values match the object diagram
3 Confirm BirthArea.Doctor refers to an Employee
4 Confirm the doctor is Flora, number 98
Provide animal food through a vending machine
4.Add the vending machine to the zoo model

Define VendingMachine with the current five fields and connect it to Zoo.

A Add VendingMachine
Progressive class diagram. Green squares mark the new VendingMachine class and its fields BagSize double, FoodCapacity double, FoodPricePerPound decimal, FoodStock double, and MoneyBalance decimal.
Add VendingMachine and its five current fields.
  • New
  • Changed
  • Removed

BagSize, FoodCapacity, and FoodStock use double. FoodPricePerPound and MoneyBalance use decimal.

B Add ZooScenario/Business Classes/VendingMachine.cs
C Add the five fields shown by the class diagram
D Preserve the current XML documentation and analyzer/suppression pattern
E Do not add purchase or refill behavior
F Check Your Work
1 Build
2 Confirm VendingMachine contains the five current fields and no methods
G Add AnimalSnackMachine to Zoo
Progressive class diagram showing a green square on the new AnimalSnackMachine relationship from Zoo to VendingMachine. The established BirthArea relationship remains unmarked.
Each Zoo object can reference its own VendingMachine through AnimalSnackMachine.
  • New
  • Changed
  • Removed
H Add the documented current AnimalSnackMachine field to Zoo
I Check Your Work
1 Build
2 Confirm the relationship compiles and BirthArea remains intact
5.Set up the Como Zoo vending machine

Create the Como AnimalSnackMachine and configure the authoritative current state.

A Create and configure the Como vending-machine object
B Create a VendingMachine object in the existing Como Zoo setup flow and store it in ComoZoo.AnimalSnackMachine
C Set BagSize = 65.0, FoodCapacity = 250.0, and FoodPricePerPound = 0.75
Completed Como vending-machine object diagram. Green squares mark the new AnimalSnackMachine object and reference plus BagSize 65.0, FoodCapacity 250.0, and FoodPricePerPound 0.75. Untouched default-valued members are omitted.
Completed Como vending-machine state. Untouched defaults are intentionally left out.
  • New
  • Changed
  • Removed
D Check Your Work
1 Inspect ComoZoo.AnimalSnackMachine
2 Confirm BagSize = 65.0, FoodCapacity = 250.0, and FoodPricePerPound = 0.75
Add the San Diego Zoo to the application
6.Reuse the same class design for the San Diego Zoo

Use the existing Zoo, Animal, Employee, Restroom, Booth, BirthingRoom, and VendingMachine classes to create a separate San Diego object graph.

A Add SanDiegoZoo
Class diagram showing MainWindow related to Zoo through the existing ComoZoo role and a new SanDiegoZoo role. A green square marks only SanDiegoZoo.
Two fields can refer to two separate objects created from the same Zoo class.
  • New
  • Changed
  • Removed
B Add the documented current SanDiegoZoo field/reference
C Check Your Work
1 Build
2 Confirm both Zoo relationships exist
D Use the supplied San Diego button path

The UI markup is not represented by the UML, so use the exact current button source:

XML

<Button x:Name="newSanDiegoZooButton" Content="New San Diego Zoo" Click="newSanDiegoZooButton_Click"/>
E Use/preserve the supplied San Diego button path and exact current control/event names
F Check Your Work
1 Confirm the New San Diego ZooDiego Zoo button is present in the supplied UI path
2 Do not add unrelated UI behavior
G Use the supplied San Diego event-handler path

The current one-line handler signature is:

C#

private void newSanDiegoZooButton_Click(object sender, RoutedEventArgs e)

The event path coordinates creation of a separate object graph. Do not copy a complete finished handler body from this walkthrough.

H Create the San Diego Zoo and supporting objects

Create the separate San Diego objects using the same class definitions and the current source values.

I Create the SanDiegoZoo Zoo object. Set Name = "San Diego Zoo" and Capacity = 3000
J Create its TicketBooth. Set TicketPrice = 25.50, then create the Attendant employee Betty with Number = 84
K Create LadiesRoom and MensRoom. Set each Capacity = 12 and use the supplied Female/Male values
L Create FeaturedAnimal as Patti. Set Sex = "Female", Age = 5, Weight = 3.27, HappinessLevel = 0, IsPregnant = true, and Type = "Platypus"
M Create AnimalSnackMachine. Set BagSize = 65.0, FoodCapacity = 250.0, and FoodPricePerPound = 1.20
N Create BirthArea. Set InitialTemperature = 77.0, MaxTemperature = 85.0, MinTemperature = 55.0, TemperatureIncrease = 0.5, and initialize Temperature from InitialTemperature. Create the Doctor employee Steve with Number = 24
Object diagram rooted at MainWindow. ComoZoo is folded existing context. A green-square-marked SanDiegoZoo object has Name San Diego Zoo and Capacity 3000. Its separate supporting objects are TicketBooth with Betty as Attendant, LadiesRoom, MensRoom, Patti as FeaturedAnimal, AnimalSnackMachine, BirthArea, and Steve as Doctor. Only intentionally initialized current values are shown; untouched default or uninitialized members are omitted.
Como and San Diego are separate Zoo objects. The San Diego supporting objects are grouped under the San Diego object to make the relationships easier to follow.
  • New
  • Changed
  • Removed

ComoZoo and SanDiegoZoo are different Zoo objects that use the same class. Their supporting objects hold separate state, so a second zoo does not require duplicate domain classes.

O Check Your Work
1 Inspect both ComoZoo and SanDiegoZoo
2 Confirm both are Zoo objects
3 Confirm the San Diego values match the object diagram/current source
4 Confirm Como retains its own existing state
5 Confirm no San-Diego-specific duplicate domain classes were introduced
7.Final Check
A Class structure
  • BirthingRoom has InitialTemperature, MaxTemperature, MinTemperature, TemperatureIncrease, Animal, Doctor, and Temperature with the current types.
  • VendingMachine has BagSize, FoodCapacity, FoodPricePerPound, FoodStock, and MoneyBalance with the current types.
  • Zoo includes BirthArea : BirthingRoom and AnimalSnackMachine : VendingMachine.
  • MainWindow includes SanDiegoZoo : Zoo.
  • No later-course design techniques were added.
B Como Zoo state
  • Original Zoo 1.1 Como state remains intact.
  • BirthArea has 77.0 / 85.0 / 55.0 / 0.5 / 77.0.
  • BirthArea.Doctor is Flora #98.
  • AnimalSnackMachine has 65.0 / 250.0 / 0.75.
C San Diego Zoo state
  • Name = San Diego ZooZoo; Capacity = 3000.
  • Ticket = 25.50; attendant = Betty #84.
  • Both restroom capacities = 12 with the supplied Female/Male values.
  • Featured animal = Patti, Female, age 5, weight 3.27, happiness 0, pregnant true, type Platypus.
  • Vending machine = 65.0 / 250.0 / 1.20.
  • Birth area = 77.0 / 85.0 / 55.0 / 0.5 / 77.0; doctor = Steve #24.
  • Como Zoo state remains independent.

Use the normal build/error-reading and already-taught inspection paths. This page does not claim your project built or ran successfully; verify that in your own project.

8.Zoo 1.2 End-Structure Class Diagram
Final Zoo 1.2 class diagram. Green squares mark BirthingRoom and its five scalar fields, its Animal and Doctor relationships, Zoo BirthArea, VendingMachine and its five scalar fields, Zoo AnimalSnackMachine, and MainWindow SanDiegoZoo. Existing Zoo 1.1 classes, members, and relationships are unmarked. There are no Changed or Removed structural items.
Final structural delta: New items only; Changed none; Removed none.
  • New
  • Changed
  • Removed
9.Submit

Open the Feedback System to continue with the current submission/readiness process.