-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAppAverage.java
More file actions
29 lines (23 loc) · 775 Bytes
/
AppAverage.java
File metadata and controls
29 lines (23 loc) · 775 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
public class AppAverage implements Observer, DisplayElement {
private float maxTemp = 0.0f;
private float minTemp = 200;
private float tempSum = 0.0f;
private int numReadings;
private WeatherData weatherdata;
public AppAverage(WeatherData weatherdata){
this.weatherdata = weatherdata;
weatherdata.registerObserver(this);
}
public void update(float temp, float humidity, float pressure){
tempSum += temp;
numReadings++;
if (temp > maxTemp)
maxTemp = temp;
if (temp < minTemp)
minTemp = temp;
display();
}
public void display(){
System.out.println("Avg/Max/Min Temperature = " + (tempSum/numReadings) + "/" + maxTemp + "/" + minTemp);
}
}