-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatisticsDisplay.java
More file actions
31 lines (25 loc) · 894 Bytes
/
StatisticsDisplay.java
File metadata and controls
31 lines (25 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class StatisticsDisplay implements Observer {
private float maxTemperature = Float.MIN_VALUE;
private float minTemperature = Float.MAX_VALUE;
private float sumTemperature = 0;
private int numReadings = 0;
public StatisticsDisplay(Subject weatherData) {
weatherData.registerObserver(this);
}
@Override
public void update(float temperature, float humidity, float pressure) {
sumTemperature += temperature;
numReadings++;
if (temperature > maxTemperature) {
maxTemperature = temperature;
}
if (temperature < minTemperature) {
minTemperature = temperature;
}
display();
}
public void display() {
System.out.println("Avg/Max/Min temperature = " + (sumTemperature / numReadings) +
"/" + maxTemperature + "/" + minTemperature);
}
}