heatindexdisplay.java

来自「深入浅出设计模式」· Java 代码 · 共 43 行

JAVA
43
字号
package headfirst.observer.weatherobservable;import java.util.Observable;import java.util.Observer;public class HeatIndexDisplay implements Observer, DisplayElement {	float heatIndex = 0.0f;	public HeatIndexDisplay(Observable observable) {		observable.addObserver(this);	}	public void update(Observable observable, Object arg) {		if (observable instanceof WeatherData) {			WeatherData weatherData = (WeatherData)observable;			float t = weatherData.getTemperature();			float rh = weatherData.getHumidity();			heatIndex = (float)				(				(16.923 + (0.185212 * t)) + 				(5.37941 * rh) - 				(0.100254 * t * rh) + 				(0.00941695 * (t * t)) + 				(0.00728898 * (rh * rh)) + 				(0.000345372 * (t * t * rh)) - 				(0.000814971 * (t * rh * rh)) +				(0.0000102102 * (t * t * rh * rh)) - 				(0.000038646 * (t * t * t)) + 				(0.0000291583 * (rh * rh * rh)) +				(0.00000142721 * (t * t * t * rh)) + 				(0.000000197483 * (t * rh * rh * rh)) - 				(0.0000000218429 * (t * t * t * rh * rh)) +				(0.000000000843296 * (t * t * rh * rh * rh)) -				(0.0000000000481975 * (t * t * t * rh * rh * rh)));			display();		}	}	public void display() {		System.out.println("Heat index is " + heatIndex);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?