Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HeadFirstDesignPatterns.Ch02TheObserverPattern.WeatherStation
- {
- class StatisticsDisplay : Observer, DisplayElement
- {
- private float maxTemp = 0.0F;
- private float minTemp = 200;
- private float tempSum = 0.0F;
- private int numReadings;
- private WeatherData weatherData;
- public StatisticsDisplay(WeatherData weatherData)
- {
- this.weatherData = weatherData;
- weatherData.RegisterObserver(this);
- }
- public void update(float temperature, float humidity, float pressure)
- {
- tempSum += temperature;
- numReadings++;
- if (temperature > maxTemp)
- {
- maxTemp = temperature;
- }
- if (temperature < minTemp)
- {
- minTemp = temperature;
- }
- display();
- }
- public void display()
- {
- Console.WriteLine(String.Format("Avg/Max/Min temperature = {0}/{1}/{2}", (tempSum / numReadings), maxTemp, minTemp));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement