Advertisement
Fhernd

HeatIndexDisplay.cs

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