Advertisement
Fhernd

ForecastDisplayWithEventsAndDelegates.cs

Mar 13th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace HeadFirstDesignPatterns.Ch02TheObserverPattern.WeatherStationWithEventsAndDelegates
  8. {
  9.     class ForecastDisplayWithEventsAndDelegates : IObserverWithEventsAndDelegates, DisplayElementWithEventsAndDelegates
  10.     {
  11.         private float currentPressure = 29.92F;
  12.         private float lastPressure;
  13.  
  14.         public void Update(float temperature, float humidity, float pressure)
  15.         {
  16.             lastPressure = currentPressure;
  17.             currentPressure = pressure;
  18.  
  19.             Display();
  20.         }
  21.  
  22.         public void Display()
  23.         {
  24.             System.Console.WriteLine("Forecast: ");
  25.             if (currentPressure > lastPressure)
  26.             {
  27.                 System.Console.WriteLine("Improving weather on the way!");
  28.             }
  29.             else if (currentPressure == lastPressure)
  30.             {
  31.                 System.Console.WriteLine("More of the same");
  32.             }
  33.             else if (currentPressure < lastPressure)
  34.             {
  35.                 System.Console.WriteLine("Watch out for cooler, rainy weather");
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement