Exemple #1
0
        private double Conversion(string MeasurementType, string conversionType, double value)
        {
            Length      length      = new Length();
            Weights     weights     = new Weights();
            Volumes     volume      = new Volumes();
            Temperature temperature = new Temperature();

            if (MeasurementType == "length")
            {
                LengthUnit unit = length.SetUnitAndConvertLength(conversionType);

                if (unit == LengthUnit.FeetToInch || unit == LengthUnit.YardToInch || unit == LengthUnit.CentimeterToInch)
                {
                    return(length.ConvertLength(unit, value));
                }
            }

            if (MeasurementType == "weight")
            {
                WeightsUnit unit = weights.SetUnitAndConvertWeights(conversionType);
                if (unit.Equals(WeightsUnit.KilogramToGrams) || unit.Equals(WeightsUnit.TonneToKilograms))
                {
                    return(weights.ConvertWeigths(unit, value));
                }
            }

            if (MeasurementType == "volume")
            {
                VolumeUnit unit = volume.SetUnitAndConvertVolume(conversionType);
                if (unit.Equals(VolumeUnit.GallonToLiter) || unit.Equals(VolumeUnit.LiterToMilliliter) || unit.Equals(VolumeUnit.MilliliterToLiter))
                {
                    return(volume.ConvertVolumes(unit, value));
                }
            }
            if (MeasurementType == "temperature")
            {
                TemperatureUnit unit = temperature.SetUnitAndConvertTemperature(conversionType);
                if (unit.Equals(TemperatureUnit.CelsiusToFahrenheit))
                {
                    return(temperature.ConvertTemperature(unit, value));
                }
            }

            return(value);
        }
Exemple #2
0
        /// <summary>
        /// Method to convert Weights
        /// </summary>
        /// <param name="unit">defines which unit used</param>
        /// <param name="temperature">defines which type of temperature</param>
        /// <returns>return calculated temperature</returns>
        public double ConvertTemperature(TemperatureUnit unit, double temperature)
        {
            try
            {
                if (unit.Equals(TemperatureUnit.CelsiusToFahrenheit))
                {
                    return(CelsiusToFahrenheit + (temperature * 1.8) - 1.8);
                }

                return(temperature);
            }
            catch (QuantityException e)
            {
                throw new QuantityException(QuantityException.ExceptionType.InvalidData, e.Message);
            }
            catch (Exception e)
            {
                throw e;
            }
        }