public ColorCodeResult CalculateOhmValue(string bandAColor, string bandBColor, string bandCColor, string bandDColor) { OhmCalculationInput ohmInput = new OhmCalculationInput(); int ohmValue = Convert.ToInt32(string.Format("{0}{1}", ohmInput.significantFigures[bandAColor], ohmInput.significantFigures[bandBColor])); int multiplier = ohmInput.multiplier[bandCColor]; double tolerance = ohmInput.tolerance[bandDColor]; double resultMax = (ohmValue * Math.Pow(10, multiplier) * (1 + tolerance)); double resultMin = (ohmValue * Math.Pow(10, multiplier) * (1 - tolerance)); ColorCodeResult ccResult = new ColorCodeResult(); ccResult.MinimumResistance = FormatResistance(resultMin); ccResult.MaximumResistance = FormatResistance(resultMax); return(ccResult); }
/// <summary> /// Calculates the minimum and maximum Ohm values of a resistor based on the band colors. /// </summary> /// <param name="bandAColor">The color of the first figure of component value band.</param> /// <param name="bandBColor">The color of the second significant figure band.</param> /// <param name="bandCColor">The color of the decimal multiplier band.</param> /// <param name="bandDColor">The color of the tolerance value band.</param> /// <returns>A custom object containing range of actual value in ohms</returns> public ColorCodeResult CalculateOhmValue(string bandAColor, string bandBColor, string bandCColor, string bandDColor) { //Intialize color-code dictionary checkers OhmCalculationInput ohmInput = new OhmCalculationInput(); //get color codes from color-code dictionaries int ohmValue = Convert.ToInt32(string.Format("{0}{1}", ohmInput.significantFigures[bandAColor], ohmInput.significantFigures[bandBColor])); int multiplier = ohmInput.multiplier[bandCColor]; double tolerance = ohmInput.tolerance[bandDColor]; // find maximum and minimum resistance values double resultMax = (ohmValue * Math.Pow(10, multiplier) * (1 + tolerance)); double resultMin = (ohmValue * Math.Pow(10, multiplier) * (1 - tolerance)); // save the results in ColorCodeResult object ColorCodeResult ccResult = new ColorCodeResult(); ccResult.MinimumResistance = FormatResistance(resultMin); ccResult.MaximumResistance = FormatResistance(resultMax); // return resistance value range. return(ccResult); }