001package headfirst.observer.WeatherStation;
002
003public class StatisticsDisplay implements Observer, DisplayElement {
004        private float maxTemp = 0.0f;
005        private float minTemp = 200;
006        private float tempSum= 0.0f;
007        private int numReadings;
008        //private WeatherData weatherData;
009
010        public StatisticsDisplay(WeatherData weatherData) {
011                //this.weatherData = weatherData;
012                weatherData.registerObserver(this);
013        }
014
015        public void update(float temp, float humidity, float pressure) {
016                tempSum += temp;
017                numReadings++;
018
019                if (temp > maxTemp) {
020                        maxTemp = temp;
021                }
022
023                if (temp < minTemp) {
024                        minTemp = temp;
025                }
026
027                display();
028        }
029
030        public void display() {
031                System.out.println("Avg/Max/Min temperature = " + (tempSum / numReadings)
032                                + "/" + maxTemp + "/" + minTemp);
033        }
034}