Example #1
0
        private bool ReadInputFuel()
        {
            if (ValidateFuelInput())
            {
                var currReading = double.Parse(textBoxCurrOdoRead.Text);
                var prevReading = double.Parse(textBoxPrevOdoRead.Text);
                var fuelAmount  = double.Parse(textBoxFuelInput.Text);
                var unitPrice   = double.Parse(textBoxLiterPriceInput.Text);

                // check if positive number
                if (currReading < 0 || prevReading < 0 || fuelAmount < 0 || unitPrice < 0)
                {
                    errorMsg = "Make sure that all numerals are positive.";
                    return(false);
                }
                // check if currReading > prevReading
                else if (currReading < prevReading)
                {
                    errorMsg = "The current odometer reading must be larger than the previous odometer reading.";
                    return(false);
                }
                else
                {
                    fuelCalculator = new FuelCalculator(currReading, fuelAmount, prevReading, unitPrice);
                    return(true);
                }
            }
            return(false);
        }