001package headfirst.observer.WeatherStation; 002 003public class HeatIndexDisplay implements Observer, DisplayElement { 004 float heatIndex = 0.0f; 005 //private WeatherData weatherData; 006 007 public HeatIndexDisplay(WeatherData weatherData) { 008 //this.weatherData = weatherData; 009 weatherData.registerObserver(this); 010 } 011 012 public void update(float t, float rh, float pressure) { 013 heatIndex = computeHeatIndex(t, rh); 014 display(); 015 } 016 017 private float computeHeatIndex(float t, float rh) { 018 float index = (float)((16.923 + (0.185212 * t) + (5.37941 * rh) - (0.100254 * t * rh) 019 + (0.00941695 * (t * t)) + (0.00728898 * (rh * rh)) 020 + (0.000345372 * (t * t * rh)) - (0.000814971 * (t * rh * rh)) + 021 (0.0000102102 * (t * t * rh * rh)) - (0.000038646 * (t * t * t)) + (0.0000291583 * 022 (rh * rh * rh)) + (0.00000142721 * (t * t * t * rh)) + 023 (0.000000197483 * (t * rh * rh * rh)) - (0.0000000218429 * (t * t * t * rh * rh)) + 024 0.000000000843296 * (t * t * rh * rh * rh)) - 025 (0.0000000000481975 * (t * t * t * rh * rh * rh))); 026 return index; 027 } 028 029 public void display() { 030 System.out.println("Heat index is " + heatIndex); 031 } 032}