001package headfirst.observer.WeatherStationObservable;
002
003import java.util.Observable;
004import java.util.Observer;
005
006public class CurrentConditionsDisplay implements Observer, DisplayElement {
007        Observable observable;
008        private float temperature;
009        private float humidity;
010
011        public CurrentConditionsDisplay(Observable observable) {
012                this.observable = observable;
013                observable.addObserver(this);
014        }
015
016        public void update(Observable obs, Object arg) {
017                if (obs instanceof WeatherData) {
018                        WeatherData weatherData = (WeatherData)obs;
019                        this.temperature = weatherData.getTemperature();
020                        this.humidity = weatherData.getHumidity();
021                        display();
022                }
023        }
024
025        public void display() {
026                System.out.println("Current conditions: " + temperature
027                                + "F degrees and " + humidity + "% humidity");
028        }
029}