Advertisement
Fhernd

HeatIndexDisplayWithEventsAndDelegates.cs

Mar 13th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 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 HeatIndexDisplayWithEventsAndDelegates : IObserverWithEventsAndDelegates, DisplayElementWithEventsAndDelegates
  10.     {
  11.         private float heatIndex = 0.0F;
  12.  
  13.         private float ComputeHeatIndex(float t, float rh)
  14.         {
  15.             float index = (float)((16.923 + (0.185212 * t) + (5.37941 * rh) - (0.100254 * t * rh) +
  16.                 (0.00941695 * (t * t)) + (0.00728898 * (rh * rh)) +
  17.                 (0.000345372 * (t * t * rh)) - (0.000814971 * (t * rh * rh)) +
  18.                 (0.0000102102 * (t * t * rh * rh)) - (0.000038646 * (t * t * t)) + (0.0000291583 *
  19.                 (rh * rh * rh)) + (0.00000142721 * (t * t * t * rh)) +
  20.                 (0.000000197483 * (t * rh * rh * rh)) - (0.0000000218429 * (t * t * t * rh * rh)) +
  21.                 0.000000000843296 * (t * t * rh * rh * rh)) -
  22.                 (0.0000000000481975 * (t * t * t * rh * rh * rh)));
  23.             return index;
  24.         }
  25.  
  26.         public void Update(float temperature, float humidity, float pressure)
  27.         {
  28.             heatIndex = ComputeHeatIndex(temperature, humidity);
  29.             Display();
  30.         }
  31.  
  32.         public void Display()
  33.         {
  34.             System.Console.WriteLine(String.Format("Heat Index: is {0}",  heatIndex));
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement