-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetAvg.java
45 lines (39 loc) · 1.18 KB
/
GetAvg.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class GetAvg implements Observer{
private double temperature;
private double humidity;
private double avgTemperature;
private double avgHumidity;
private double totalTemperature;
private double totalHumidity;
private double count;
public GetAvg(){
totalHumidity=0.0;
totalTemperature=0.0;
count=0.0;
}
@Override
public void update(double updatedTemperature,double updatedHumidity)
{
this.temperature=updatedTemperature;
this.humidity=updatedHumidity;
totalTemperature+=updatedTemperature;
totalHumidity+=updatedHumidity;
count+=1;
}
@Override
public void register(WeatherStation weatherStation)
{
weatherStation.register(this);
}
@Override
public void unregister(WeatherStation weatherStation)
{
weatherStation.unregister(this);
}
public void showAvg(){
avgTemperature=totalTemperature/count;
avgHumidity=totalHumidity/count;
System.out.println("Average temperature of last "+count+" hours = "+avgTemperature);
System.out.println("Average humidity of last "+count+" hours = "+avgHumidity);
}
}