public ActionResult CalculateResistenceValue(string _bandAColor, string _bandBColor, string _bandCColor, string _bandDColor) { try { ResistenceValues resistenceValues = _ohmCalculator.CalculateOhmValue(_bandAColor, _bandBColor, _bandCColor, _bandDColor); return(Json(new { minimumValue = resistenceValues.MinimumResistance, maximumValue = resistenceValues.MaximumResistance })); } catch (Exception ex) { return(Json(new { error = "Resistence Calculation Error: " + ex.Message })); } }
ResistenceValues IOhmCalculator.CalculateOhmValue(string bandAColor, string bandBColor, string bandCColor, string bandDColor) { ResistenceValues resistenceValues = new ResistenceValues(); int bandAColorValue = _ohmColorStaticValues.SignificantFigures(bandAColor); int bandBColorValue = _ohmColorStaticValues.SignificantFigures(bandBColor); int bandCColorValue_Multiplier = _ohmColorStaticValues.Multifplier(bandCColor); double bandDColorValue_Tolarance = _ohmColorStaticValues.Tolerance(bandDColor); bandDColorValue_Tolarance = bandDColorValue_Tolarance == 0 ? 1 : bandDColorValue_Tolarance; resistenceValues.MaximumResistance = FormatResistance(Convert.ToInt32(string.Format("{0}{1}", bandAColorValue, bandBColorValue)) * (Math.Pow(10, bandCColorValue_Multiplier) * (1 + bandDColorValue_Tolarance))); resistenceValues.MinimumResistance = FormatResistance(Convert.ToInt32(string.Format("{0}{1}", bandAColorValue, bandBColorValue)) * (Math.Pow(10, bandCColorValue_Multiplier) * (1 - bandDColorValue_Tolarance))); return(resistenceValues); }