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.WeatherStationWithEventsAndDelegates
- {
- class StatisticsDisplayWithEventsAndDelegates : IObserverWithEventsAndDelegates, DisplayElementWithEventsAndDelegates
- {
- private float maxTemp = 0.0F;
- private float minTemp = 200;
- private float tempSum = 0.0F;
- private int numReadings;
- 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()
- {
- System.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