001package headfirst.observer.WeatherStation;
002
003public class ForecastDisplay implements Observer, DisplayElement {
004        private float currentPressure = 29.92f;
005        private float lastPressure;
006        //private WeatherData weatherData;
007
008        public ForecastDisplay(WeatherData weatherData) {
009                //this.weatherData = weatherData;
010                weatherData.registerObserver(this);
011        }
012
013        public void update(float temp, float humidity, float pressure) {
014                lastPressure = currentPressure;
015                currentPressure = pressure;
016
017                display();
018        }
019
020        public void display() {
021                System.out.print("Forecast: ");
022                if (currentPressure > lastPressure) {
023                        System.out.println("Improving weather on the way!");
024                } else if (currentPressure == lastPressure) {
025                        System.out.println("More of the same");
026                } else if (currentPressure < lastPressure) {
027                        System.out.println("Watch out for cooler, rainy weather");
028                }
029        }
030}