32 lines
767 B
D
32 lines
767 B
D
|
module observer.currentconditionsdisplay;
|
||
|
import observer.displayelement;
|
||
|
import observer.observer;
|
||
|
import observer.weatherdata;
|
||
|
import std.stdio : writeln;
|
||
|
import std.format : format;
|
||
|
|
||
|
class CurrentConditionsDisplay : Observer, DisplayElement
|
||
|
{
|
||
|
private:
|
||
|
float temperature;
|
||
|
float humidity;
|
||
|
WeatherData weatherData;
|
||
|
public:
|
||
|
this(WeatherData weatherData)
|
||
|
{
|
||
|
weatherData.registerObserver(this);
|
||
|
}
|
||
|
|
||
|
override void update(float temperature, float humidity, float pressure)
|
||
|
{
|
||
|
this.temperature = temperature;
|
||
|
this.humidity = humidity;
|
||
|
display();
|
||
|
}
|
||
|
|
||
|
override void display()
|
||
|
{
|
||
|
writeln("Current conditions: %3.1f".format(temperature), "F degrees and %3.1f%% humidity".format(humidity));
|
||
|
}
|
||
|
}
|