public static void ConfigureThermometer(Thermometer thermometer) { List<TemperatureThreshold> temperatureThresholdList = new List<TemperatureThreshold> { new TemperatureThreshold { Name = "Freezing Threshold", Temperature = 0, Tolerance = 0.5, Direction = TemperatureDirection.Decreasing }, new TemperatureThreshold { Name = "Boiling Threshold", Temperature = 100, Tolerance = 0.5, Direction = TemperatureDirection.Increasing }, new TemperatureThreshold { Name = "Room Temperature Threshold", Temperature = 20, Tolerance = 0.5, Direction = TemperatureDirection.Increasing } }; // Add temperature thresholds thermometer.AddThresholds(temperatureThresholdList); // Add event handler thermometer.TemperatureThresholdReached += HandleThermometerThresholdReached; }
static void Main() { Thermometer thermometer = new Thermometer(); ConfigureThermometer(thermometer); Console.WriteLine("\nWelcome to the temperature monitor.\n"); Console.WriteLine(thermometer.ToString()); Console.WriteLine("Temperature values must be followed by a space and temperature type (C or F).\n"); bool done; do { Console.Write("Enter temperature (or blank line to exit) >"); string input = Console.ReadLine(); done = string.IsNullOrWhiteSpace(input); if (done) { continue; } double temperature; bool readTemperature = ReadTemperature(input, out temperature); if (readTemperature) { thermometer.SetTemperature(temperature); } else { Console.WriteLine("Could not parse input. Try again."); } } while (!done); Console.WriteLine("\nPress any key to exit."); Console.ReadKey(); }