Exemplo n.º 1
0
        // Static Constructor
        static StandardCoinMetrics()
        {
            _allCoinMetrics = new StandardCoinMetrics[3];

            _allCoinMetrics[0] = new StandardCoinMetrics(
                name: "Nickel",
                valueCents: 5,
                minWeightGrams: 4.990f,
                maxWeightGrams: 5.020f,
                minDiameterMm: 21.10f,
                maxDiameterMm: 21.30f);

            _allCoinMetrics[1] = new StandardCoinMetrics(
                name: "Dime",
                valueCents: 10,
                minWeightGrams: 2.250f,
                maxWeightGrams: 2.280f,
                minDiameterMm: 17.70f,
                maxDiameterMm: 18.00f);

            _allCoinMetrics[2] = new StandardCoinMetrics(
                name: "Quarter",
                valueCents: 25,
                minWeightGrams: 5.660f,
                maxWeightGrams: 5.680f,
                minDiameterMm: 24.10f,
                maxDiameterMm: 25.40f);
        }
Exemplo n.º 2
0
        /// <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);
        }