48 lines
1.1 KiB
D
48 lines
1.1 KiB
D
module observer.request.statiscticdisplay;
|
|
|
|
import observer.request.displayelement;
|
|
import observer.request.observer;
|
|
import observer.request.weatherdata;
|
|
import std.stdio : writeln;
|
|
import std.format : format;
|
|
|
|
class StatisticsDisplay : Observer, DisplayElement
|
|
{
|
|
private:
|
|
float maxTemp = 0.0f;
|
|
float minTemp = 200;
|
|
float tempSum= 0.0f;
|
|
int numReadings;
|
|
WeatherData weatherData;
|
|
public:
|
|
this(WeatherData weatherData)
|
|
{
|
|
this.weatherData = weatherData;
|
|
weatherData.registerObserver(this);
|
|
}
|
|
|
|
override void update()
|
|
{
|
|
tempSum += weatherData.getTemperature;
|
|
numReadings++;
|
|
|
|
if (weatherData.getTemperature > maxTemp)
|
|
{
|
|
maxTemp = weatherData.getTemperature;
|
|
}
|
|
|
|
if (weatherData.getTemperature < minTemp)
|
|
{
|
|
minTemp = weatherData.getTemperature;
|
|
}
|
|
|
|
display();
|
|
}
|
|
|
|
override void display()
|
|
{
|
|
writeln("Avg/Max/Min temperature = ", (tempSum / numReadings), '/', maxTemp, '/', minTemp);
|
|
// writeln("Avg/Max/Min temperature = ".format(temperature), "F degrees and %3.1f%% humidity".format(humidity));
|
|
}
|
|
}
|