Exemple #1
0
        public static Fahrenheit operator -(Fahrenheit fahrenheit, Kelvin kelvin)
        {
            Fahrenheit aux = new Fahrenheit(fahrenheit.GetTemperatura() - ((Fahrenheit)kelvin).GetTemperatura());

            return(aux);
        }
Exemple #2
0
        public static Fahrenheit operator -(Fahrenheit fahrenheit, Celsius celsius)
        {
            Fahrenheit aux = new Fahrenheit(fahrenheit.GetTemperatura() - ((Fahrenheit)celsius).GetTemperatura());

            return(aux);
        }
        static void Main(string[] args)
        {
            Console.Title = "Exercise 21°";

            Kelvin     kTemperature = new Kelvin(298.15);
            Celsius    cTemperature = new Celsius(25);
            Fahrenheit fTemperature = new Fahrenheit(77);

            Celsius cTemperature2 = new Celsius(25);


            Kelvin     kNew = new Kelvin();
            Celsius    cNew = new Celsius();
            Fahrenheit fNew = new Fahrenheit();

            Console.WriteLine("########## Temperature Convertions ##########");
            /*Fahrenheite -> Kelvin*/
            kNew = (Kelvin)fTemperature;
            double kNewDouble = kNew.GetAmount();

            Console.WriteLine($"Fahrenheit: {fTemperature.GetAmount()}° - Kelvin: {Math.Round(kNewDouble, 2)}°");

            /*Fahrenheite -> Celsius*/
            cNew = (Celsius)fTemperature;
            double cNewDouble = cNew.GetAmount();

            Console.WriteLine($"Fahrenheit: {fTemperature.GetAmount()}° - Celsius: {cNewDouble}°\n");

            /*Celsius -> Kelvin*/
            kNew       = (Kelvin)cTemperature;
            kNewDouble = kNew.GetAmount();
            Console.WriteLine($"Celsius: {cTemperature.GetAmount()}° - Kelvin: {kNewDouble}°");

            /*Celsius -> Fahrenheite*/
            fNew = (Fahrenheit)cTemperature;
            double fNewDouble = fNew.GetAmount();

            Console.WriteLine($"Celsius: {cTemperature.GetAmount()}° - Fahrenheit: {fNewDouble}°\n");

            /*Kelvin -> Celsius*/
            cNew       = (Celsius)kTemperature;
            cNewDouble = cNew.GetAmount();
            Console.WriteLine($"Kelvin: {kTemperature.GetAmount()}° - Celsius: {cNewDouble}°");

            /*Kelvin -> Fahrenheit*/
            fNew       = (Fahrenheit)kTemperature;
            fNewDouble = fNew.GetAmount();
            Console.WriteLine($"Kelvin: {kTemperature.GetAmount()}° - Fahrenheit: {Math.Round(fNewDouble, 2)}°\n");

            Console.WriteLine("########## Temperature Equality ##########");
            /*Equally: Celsius -> Fahrenheit*/
            Console.WriteLine($"Celsius: {cTemperature.GetAmount()}° - Fahrenheit: {fTemperature.GetAmount()}° -> Equally: {cTemperature == fTemperature}");
            /*Equally: Celsius -> Kelvin*/
            Console.WriteLine($"Celsius: {cTemperature.GetAmount()}° - Kelvin: {kTemperature.GetAmount()}° -> Equally: {cTemperature == kTemperature}");
            /*Equally: Celsius -> Celsius*/
            Console.WriteLine($"Celsius: {cTemperature.GetAmount()}° - Celsius: {cTemperature2.GetAmount()}° -> Equally: {cTemperature == cTemperature2}\n");

            Console.WriteLine("########## Temperature Addition ##########");
            Celsius sumCelsius = new Celsius();

            sumCelsius = cTemperature + fTemperature;
            Console.WriteLine($" {cTemperature.GetAmount()}°C + {fTemperature.GetAmount()}°F: {Math.Round(sumCelsius.GetAmount(), 2)}° Celsius");
            sumCelsius = cTemperature + kTemperature;
            Console.WriteLine($" {cTemperature.GetAmount()}°C + {kTemperature.GetAmount()}°K: {Math.Round(sumCelsius.GetAmount(), 2)}° Celsius");

            Console.ReadKey(true);
        }