Ejemplo n.º 1
0
        internal static void insertANumberInValidRange(float i_Min, float i_Max)
        {
            ValueOutOfRangeException rangeException = new ValueOutOfRangeException(i_Min, i_Max);

            Console.WriteLine(
                @rangeException.Message);
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------//
        private float getValidInputValueInRange(float i_MinValue, float i_MaxValue)
        {
            string userInputChoice    = Console.ReadLine();
            float  userInputNumerical = 0;

            while (!float.TryParse(userInputChoice, out userInputNumerical) ||
                   ValueOutOfRangeException.ValueOutOfRange(userInputNumerical, i_MaxValue, i_MinValue))
            {
                Console.WriteLine(@"Choice is out of boundaries, please enter input again in the range {0} to {1}: ",
                                  i_MinValue, i_MaxValue);
                userInputChoice = Console.ReadLine();
            }

            return(userInputNumerical);
        }
Ejemplo n.º 3
0
        private AutoRepairShop.VehicleInShop.eVehicleStatus?getStatus()
        {
            AutoRepairShop.VehicleInShop.eVehicleStatus?returnStatus;
            PrintingUtils.PrintListOfEnum(
                "Please write below the vehicle status:",
                typeof(AutoRepairShop.VehicleInShop.eVehicleStatus));
            string status  = Console.ReadLine();
            bool   isValid = Enum.TryParse(status, out AutoRepairShop.VehicleInShop.eVehicleStatus result) &&
                             Enum.IsDefined(typeof(AutoRepairShop.VehicleInShop.eVehicleStatus), result);

            if (isValid)
            {
                returnStatus = result;
            }
            else
            {
                string errorMessage         = "You have to choose from the following options";
                ValueOutOfRangeException ex = new ValueOutOfRangeException(1, 3, errorMessage);
                throw new FormatException("Fail parsing the vehicle status", ex);
            }

            return(returnStatus);
        }
Ejemplo n.º 4
0
        private List <float> checkAndCreateAirPressureList(byte i_NumOfTires, float i_MaxTirePressure)
        {
            List <float> airPressure = new List <float>(i_NumOfTires);
            string       airPressureToAdd;
            int          currentTire = 0;

            while (airPressure.Count < i_NumOfTires)
            {
                Console.WriteLine("Please enter the air pressure of tire number {0}", airPressure.Count + 1);
                airPressureToAdd = Console.ReadLine();
                try
                {
                    airPressure.Add(float.Parse(airPressureToAdd));
                    if (airPressure[currentTire] > i_MaxTirePressure)
                    {
                        ValueOutOfRangeException ex = new ValueOutOfRangeException();

                        throw ex;
                    }

                    currentTire++;
                }
                catch (ValueOutOfRangeException)
                {
                    Console.WriteLine("Invalid value.");
                    airPressure.RemoveAt(currentTire);
                    currentTire--;
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid value.");
                }
            }

            return(airPressure);
        }
Ejemplo n.º 5
0
        public void PrintRangeMsgError(ValueOutOfRangeException i_Ex)
        {
            string message = string.Format("{0} [{1}-{2}]", i_Ex.Message, i_Ex.MinValue.ToString(), i_Ex.MaxValue.ToString());

            PrintMessage(message);
        }