/// <summary> /// Coin is valid if in range of weight and diameter /// </summary> /// <param name="coin"></param> /// <param name="standardCoinMetrics"></param> /// <returns></returns> private static bool IsValidCoin(SampleCoin coin, StandardCoinMetrics standardCoinMetrics) { Debug.Assert(coin != null, "coin != null"); Debug.Assert(standardCoinMetrics != null); var actWeight = coin.WeightGrams; var actDiameter = coin.DiameterMm; var minWeight = standardCoinMetrics.MinWeightGrams; var maxWeight = standardCoinMetrics.MaxWeightGrams; var minDiameter = standardCoinMetrics.MinDiameterMm; var maxDiameter = standardCoinMetrics.MaxDiameterMm; bool weightOk = (minWeight <= actWeight && actWeight <= maxWeight); bool diameterOk = (minDiameter <= actDiameter && actDiameter <= maxDiameter); return(weightOk && diameterOk); }
/// <summary> /// Examines coin. If IsValid, then read MatchedName and MatchedValueCents /// </summary> /// <param name="coin">Sample coin</param> public static void ExamineCoin(SampleCoin coin) { Debug.Assert(coin != null, "coin may not be null"); // Sets _matchedIndex _matchedIndex = -1; for (_matchedIndex = _allCoinMetrics.Length - 1; _matchedIndex >= 0; _matchedIndex--) { var item = _allCoinMetrics[_matchedIndex]; if (IsValidCoin(coin, item)) { break; } } }