41 lines
967 B
D
41 lines
967 B
D
module observer.forecastdisplay;
|
|
|
|
import observer.displayelement;
|
|
import observer.observer;
|
|
import observer.weatherdata;
|
|
import std.stdio : write, writeln;
|
|
import std.format : format;
|
|
|
|
class ForecastDisplay : Observer, DisplayElement
|
|
{
|
|
private:
|
|
float currentPressure = 29.92f;
|
|
float lastPressure;
|
|
WeatherData weatherData;
|
|
public:
|
|
this(WeatherData weatherData)
|
|
{
|
|
this.weatherData = weatherData;
|
|
weatherData.registerObserver(this);
|
|
}
|
|
|
|
override void update()
|
|
{
|
|
lastPressure = currentPressure;
|
|
currentPressure = weatherData.getPressure;
|
|
display();
|
|
}
|
|
|
|
override void display()
|
|
{
|
|
write("Forecast: ");
|
|
if (currentPressure > lastPressure) {
|
|
writeln("Improving weather on the way!");
|
|
} else if (currentPressure == lastPressure) {
|
|
writeln("More of the same");
|
|
} else if (currentPressure < lastPressure) {
|
|
writeln("Watch out for cooler, rainy weather");
|
|
}
|
|
}
|
|
}
|