Exemplo n.º 1
0
        static void Main(string[] args)
        {
            /**********************************************************************************************
             *
             *  Assumed that the data is on streaming
             *  NOTE: you must initialize the Thermometer class and set its property first before you start
             *  read the temperature
             *
             * ************************************************************************************************/

            Thermometer thermometer = new Thermometer(-30, 30, 8); // initialize Thermometer class
            Random      rand        = new Random();                //use Random class for generate sample data

            //thermometer.FreezingPoint = -20;          // other way of setting freezing point
            //thermometer.BoilingPoint = 20;            // other way of setting boiling point
            //thermometer.CustomThresholdPoint = 8;     // other way of setting custom threshold point
            //thermometer.ShowTriggeredPointOnce = true;  // show a freezing, boiling & custom threshold point once

            while (true) // use while loop to make it like a streaming
            {
                var temperatureObj = thermometer.ReadTemperature(rand.Next(-20, 20), ThresholdPoint.FreezingPoint);

                Console.WriteLine($"{temperatureObj.Value} {temperatureObj.prefix} {temperatureObj.Message}");
                Thread.Sleep(1500);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Thermometer thermometer = new Thermometer();

            thermometer.celciusToFahrenheit(32);
            Console.WriteLine("hasil : " + thermometer.result);

            thermometer.fahrenheitToCelcius(140);
            Console.WriteLine("hasil : " + thermometer.result);

            thermometer.celciusToKelvin(3);
            Console.WriteLine("hasil : " + thermometer.result);
        }
Exemplo n.º 3
0
        public static async Task Main()
        {
            using (var thermometer = new Thermometer())
            {
                var subscribers = new[]
                {
                    CreateSubscriber(0, celcius => celcius, "°C"),
                    CreateSubscriber(1, celcius => ((celcius * 9) / 5) + 32, "°F"),
                    CreateSubscriber(2, celcius => celcius + 273.15, "°K")
                };

                foreach (var subscriber in subscribers)
                {
                    thermometer.TemperatureChanged += subscriber;
                }

                Console.WriteLine("Press any key to stop the program.");
                await Task.Delay(2000);

                thermometer.StartMonitoring();
                Console.ReadKey();
            }
        }