⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statisticsdisplay.java

📁 关于天气预报的一个迭代子模式的源代码
💻 JAVA
字号:
package headfirst.observer.weather;import java.util.*;public class StatisticsDisplay implements Observer, DisplayElement {	private float maxTemp = 0.0f;	private float minTemp = 200;	private float tempSum= 0.0f;	private int numReadings;	private WeatherData weatherData;	public StatisticsDisplay(WeatherData weatherData) {		this.weatherData = weatherData;		weatherData.registerObserver(this);	}	public void update(float temp, float humidity, float pressure) {		tempSum += temp;		numReadings++;		if (temp > maxTemp) {			maxTemp = temp;		} 		if (temp < minTemp) {			minTemp = temp;		}		display();	}	public void display() {		System.out.println("Avg/Max/Min temperature = " + (tempSum / numReadings)			+ "/" + maxTemp + "/" + minTemp);	}}

⌨️ 快捷键说明

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