10-152-312 - Object-Oriented Programming 2

4.1 Zoo Assignment

Starting .zip File.

  1. Unzip the OOP2_4.1Zoo zip file.
  2. Rename the folder, changing "LastName" to your last name.
  3. Open the contained solution (.sln) file and examine the code in preparation for making further changes as specified below.

Adding birthing room temperature controls to MainWindow

  1. Add the following controls to the MainWindow as shown in the wireframe
    1. A border called birthingRoomTemperatureBorder with default Background of Red
    2. A label called birthingRoomTemperatureLabel
    3. A button called increaseTemperatureButton
    4. A button called decreaseTemperatureButton
    5. All controls should stay on the bottom and the right side of the window as it stretches
  2. Add a click event to both buttons
    1. The increase button should increment the birthing room temperature by 1
    2. The decrease button should decrement the birthing room temperature by 1

Dynamically updating the birthing room temperature in the console

  1. Create a BirthingRoomDelegate that takes a BirthingRoom as a parameter
  2. In the BirthingRoom, add a BirthingRoomDelegate auto-property called OnTemperatureChange
    1. If the delegate is not null, call it when the birthing room's temperature is changed
  3. In the Zoo, add a method called BirthingRoomTemperatureChanged and plug it in to the birthing room's BirthingRoomDelegate
    1. Add a BirthingRoomDelegate full property (field plus a read/write property) called OnBirthingRoomTemperatureChange
    2. If OnBirthingRoomTemperatureChange is not null, call it from the BirthingRoomTemperatureChanged method
  4. In the console, add a method called UpdateBirthingRoomTemperature
    1. Inside the method, write to the console the current temperature of the passed-in birthing room
    2. Plug it in to the zoo's OnBirthingRoomTemperatureChange delegate after the zoo is created in the "start" command
  5. In the console's "temperature" command, remove the code that writes the temperature to the console
  6. Run the console application
    1. Create the zoo (using the "start" command)
    2. Update the temperature to 80 degrees
    3. A message about the updated temperature should be written to the console

Dynamically updating the birthing room temperature in the MainWindow

  1. Add a method to the MainWindow called UpdateBirthingRoomTemperature that takes a BirthingRoom as a parameter and add the following code:
  2. Create a private method in MainWindow for attaching delegates called AttachDelegates
    1. In it, attach the UpdateBirthingRoomTemperature method to the zoo's OnBirthingRoomTemperatureChange delegate
    2. Call AttachDelegates wherever a zoo is loaded or created
  3. Run the WPF application
    1. Click the increase button
    2. The label should update with the new temperature and the border should grow and change color as the temperature changes
    3. Click the decrease button
    4. The label should update with the new temperature and the border should shrink and change color as the temperature changes

Dynamically updating the guest list box

  1. Remove the PopulateGuestListBox() method and all calls to it
  2. Define a Guest delegate
  3. Create a GuestDelegate field called onTextChange and a read/write property for it in Guest
  4. Call the delegate when displayed fields change, including:
    1. Age
    2. Name
  5. Money balance should also update dynamically when it is changed
    1. Define a Wallet delegate
    2. Create a read/write WalletDelegate property in Wallet called OnMoneyBalanceChange
    3. Call the delegate whenever the money balance changes
    4. Create a method in Guest called OnWalletMoneyBalanceChange that calls the Guest's text change delegate
    5. Attach the Guest's OnWalletMoneyBalanceChange method to the Wallet's delegate
  6. Create two GuestDelegate fields in Zoo called onAddGuest and onRemoveGuest and read/write properties for them
  7. Call the add delegate when a guest is added to the zoo
  8. Call the remove delegate when a guest is removed from the zoo
  9. Create a method on MainWindow to respond to the Zoo's removal of guests that removes the passed-in guest from the list box
  10. Create a method on MainWindow to respond to the Zoo's adding of guests that adds the passed-in guest to the list box
  11. Attach the window's add and remove guest methods to the Zoo's delegates in the AttachDelegates method
  12. Create a method on MainWindow called UpdateGuestDisplay to respond to Guest's delegate and repaint the list box
    1. Get the index of the passed-in guest
    2. If the index is greater than or equal to 0, then:
      1. First set the item at that index in the list box to null
      2. Then set the item at that index in the list box to the passed-in guest
    3. Wrap this method's code inside the Dispatcher's Invoke method, as it will eventually be triggered by a timer thread
  13. Attach the UpdateGuestDisplay method to the Guest's OnTextChange delegate in the MainWindow's OnAddGuest method

Dynamically updating the animal list box

  1. Use delegates to get the animal list box to update dynamically
  2. Use the steps for updating the guest list box as a guide

Moving animals using delegates

  1. This series of delegates will be similar to the birthing room temperature delegates
  2. ICageable will have a CageableDelegate on it that Guest and Animal must implement
  3. Those delegates attach to a method in Cage that calls its own CageableDelegate called OnCageableUpdate
  4. The delegate should be plugged in in the Cage's Add method and unplugged in the Cage's Remove method
  5. The CageWindow should plug in the cage's delegate to its Update method in the constructor
  6. In the Remove method, unplug the Update method from the animal's move delegate
  7. Remove the IObserver and ISubject interfaces and remove the Observers package

Serializing and deserializing delegates

  1. In the console, add a method called AttachDelegates
    1. Pass in a zoo and plug in the UpdateBirthingRoomTemperature method to the zoo's OnBirthingRoomTemperatureChange delegate
    2. Call AttachDelegates when a zoo is started and loaded
  2. Add the NonSerialized attribute to all delegate fields in Guest, Animal and Zoo
  3. Ensure that the MainWindow's AttachDelegates method is called after a zoo is created or loaded from a file
  4. Create a method in Zoo called OnDeserialized (do not mark it with the OnDeserialized attribute)
    1. In the method, call the zoo's OnBirthingRoomTemperatureChange delegate if it is not null
    2. Call the zoo's OnAddAnimal delegate for each animal if the delegate is not null
    3. Call the zoo's OnAddGuest delegate for each guest if the delegate is not null
    4. Call the method after a zoo is loaded from a file and after the delegates are attached
  5. Run the WPF and console applications
    1. Load a saved file
    2. Delegates should work immediately on deserialization

4.1 Zoo Assignment: Wireframe

Design the user interface per the following diagram.

PNG image of 4.1 Zoo wireframe

Grading and Submission

  1. Build/compile your program
  2. Debug/test your program against the following rubric:
  3. PNG image of 4.1 Zoo rubric
  4. Make your code StyleCop-compliant
  5. Close your Visual Studio solution
  6. Compress your Visual Studio solution to a zip file
  7. Submit the zip file via Blackboard