Ejemplo n.º 1
0
        public static void CheckIfInTheRange(float i_Value, float i_UpperBound)
        {
            bool maxLevel = false;

            ValueOutOfRangeException.MaxValue = i_UpperBound;
            ValueOutOfRangeException.MinValue = 0;

            if (i_Value == i_UpperBound)
            {
                maxLevel = true;

                if (ValueOutOfRangeException.LowerBoundRelationIsInvalid(i_Value, maxLevel))
                {
                    throw new ValueOutOfRangeException();
                }
            }

            else
            {
                if (ValueOutOfRangeException.IsNotInTheScope(i_Value, maxLevel))
                {
                    throw new ValueOutOfRangeException();
                }
            }
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------//
        private Exception findExceptionsInAnswers(List <string> i_Answers, out int o_LicenseType, out int o_EngineVolume)
        {
            Exception exception = null;

            o_LicenseType = o_EngineVolume = -1;

            if (!int.TryParse(i_Answers[0], out o_LicenseType))
            {
                exception        = new FormatException("Format of input of the license type isn't valid, please try again: ");
                exception.Source = "0";
            }
            else if (ValueOutOfRangeException.ValueOutOfRange(o_LicenseType, 4, 1))
            {
                exception        = new ValueOutOfRangeException(4, 1, "License type for the motorcycle is out of range, please try again: ", exception);
                exception.Source = "0";
            }
            if (!int.TryParse(i_Answers[1], out o_EngineVolume))
            {
                exception        = new FormatException("Format of input engine volume isn't valid, please try again: ", exception);
                exception.Source = "1";
            }
            else if (ValueOutOfRangeException.ValueOutOfRange(o_EngineVolume, 1500, 1))
            {
                exception        = new ValueOutOfRangeException(1500, 1, "Engine volume for the motorcycle is out of range, please try again: ");
                exception.Source = "1";
            }

            return(exception);
        }
Ejemplo n.º 3
0
        //-----------------------------------------------------------------//
        private Exception findExceptionsInAnswers(List <string> i_Answers, out char o_AnswerBool, out float o_BaggageCapacity)
        {
            Exception exception = null;

            o_AnswerBool      = ' ';
            o_BaggageCapacity = -1;

            if (!char.TryParse(i_Answers[0], out o_AnswerBool))
            {
                exception        = new FormatException("Format of input of the hazardous goods isn't valid, please try again: ");
                exception.Source = "0";
            }
            else if (!o_AnswerBool.Equals('Y') && !o_AnswerBool.Equals('y') &&
                     !o_AnswerBool.Equals('N') && !o_AnswerBool.Equals('n'))
            {
                exception        = new ArgumentException("The argument you chose for the truck's hazardous carrying is invalid, please try again: ");
                exception.Source = "0";
            }

            if (!float.TryParse(i_Answers[1], out o_BaggageCapacity))
            {
                exception        = new FormatException("Format of input of the baggage capacity isn't valid, please try again: ", exception);
                exception.Source = "1";
            }
            else if (o_BaggageCapacity < 0)
            {
                exception        = new ValueOutOfRangeException(1000000, 1, "Baggage capacity for the truck is out of range, please try again:", exception);
                exception.Source = "1";
            }

            return(exception);
        }
Ejemplo n.º 4
0
        //-----------------------------------------------------------------//
        private Exception findExceptionsInAnswers(List <string> i_Answers, out int o_ColorChoice, out int o_AmountOfDoors)
        {
            Exception exception = null;

            o_ColorChoice = o_AmountOfDoors = -1;

            if (!int.TryParse(i_Answers[0], out o_ColorChoice))
            {
                exception        = new FormatException("Format of input of the color isn't valid, please try again: ");
                exception.Source = "0";
            }
            else if (ValueOutOfRangeException.ValueOutOfRange(o_ColorChoice, 4, 1))
            {
                exception        = new ValueOutOfRangeException(4, 1, "Color choice for the car is out of range, please try again: ", exception);
                exception.Source = "0";
            }

            if (!int.TryParse(i_Answers[1], out o_AmountOfDoors))
            {
                exception        = new FormatException("Format of input of the number of doors isn't valid, please try again: ", exception);
                exception.Source = "1";
            }
            else if (ValueOutOfRangeException.ValueOutOfRange(o_AmountOfDoors, 5, 2))
            {
                exception        = new ValueOutOfRangeException(5, 1, "Number of doors for the car is out of range, please try again: ", exception);
                exception.Source = "1";
            }

            return(exception);
        }
Ejemplo n.º 5
0
        public void ChargeBattery(float i_HowMuchToCharge)
        {
            if (this.m_CurrentState + i_HowMuchToCharge > this.r_MaxCapacity)
            {
                ValueOutOfRangeException valueOutOfRange = new ValueOutOfRangeException(this.r_MaxCapacity - this.m_CurrentState, 0f);
                throw valueOutOfRange;
            }

            this.m_CurrentState += i_HowMuchToCharge;
        }
Ejemplo n.º 6
0
 public void Inflate(float i_AirPressureToAdd)
 {
     if (i_AirPressureToAdd + m_CurrentAirPressure > r_MaxAirPressure)
     {
         ValueOutOfRangeException ex = new ValueOutOfRangeException(r_MaxAirPressure - m_CurrentAirPressure, 0f);
         throw ex;
     }
     else
     {
         m_CurrentAirPressure += i_AirPressureToAdd;
     }
 }
Ejemplo n.º 7
0
 public void ChargeCar(float i_HoursToCharge)
 {
     try
     {
         m_ElectricData.ChargeBattery(i_HoursToCharge);
     }
     catch (Exception e)
     {
         ValueOutOfRangeException valueOutOfRangeException = new ValueOutOfRangeException(e, i_HoursToCharge, 0f, r_MaxHoursOfBattery);
         throw valueOutOfRangeException;
     }
 }
Ejemplo n.º 8
0
 public override void CreatEnrgey(float i_RemainingEnergy, float i_MaxEnergy)
 {
     if (i_RemainingEnergy < 0 || i_RemainingEnergy > m_MaximumBatteryTime)
     {
         m_TimeRemainingBattery = i_RemainingEnergy;
     }
     else
     {
         ValueOutOfRangeException value = new ValueOutOfRangeException(0, m_MaximumBatteryTime);
         throw value;
     }
     m_MaximumBatteryTime = i_MaxEnergy;
 }
Ejemplo n.º 9
0
        public static void RefillIfNotOverflowOrNegativeInput(ref float i_CurrentLevel, float i_ValueToAdd, float i_MaxLevel)
        {
            bool mustBePositive = true;

            if (ValueOutOfRangeException.LowerBoundRelationIsInvalid(i_ValueToAdd, mustBePositive) == true)
            {
                throw new ValueOutOfRangeException();//Add an appropriate message
            }
            float refill = i_CurrentLevel + i_ValueToAdd;

            CheckIfInTheRange(refill, i_MaxLevel);
            i_CurrentLevel = refill;
        }
Ejemplo n.º 10
0
 public override void CreatEnrgey(float i_RemainingEnergy, float i_MaxEnergy)
 {
     if (m_CurrentFuelQuantity < 0 || m_CurrentFuelQuantity > m_MaximumFuelQuantity)
     {
         ValueOutOfRangeException value = new ValueOutOfRangeException(0, m_MaximumFuelQuantity);
         throw value;
     }
     else
     {
         m_CurrentFuelQuantity = i_RemainingEnergy;
     }
     m_MaximumFuelQuantity = i_MaxEnergy;
 }
Ejemplo n.º 11
0
        public void ChargingBattery(float i_AddCharging)
        {
            float newTimeBattery = m_TimeRemainingBattery + i_AddCharging;

            if (newTimeBattery <= m_MaximumBatteryTime)
            {
                m_TimeRemainingBattery = newTimeBattery;
            }
            else
            {
                ValueOutOfRangeException value = new ValueOutOfRangeException(0, m_MaximumBatteryTime);
                throw value;
            }
        }
Ejemplo n.º 12
0
        public void Refueling(FuelTypes i_FuelType, float i_AddFuel)
        {
            float newFuelQuantity = m_CurrentFuelQuantity + i_AddFuel;

            if (m_FuelType == i_FuelType && newFuelQuantity <= m_MaximumFuelQuantity)
            {
                m_CurrentFuelQuantity = newFuelQuantity;
            }
            else
            {
                ValueOutOfRangeException value = new ValueOutOfRangeException(0, m_MaximumFuelQuantity);
                throw value;
            }
        }
Ejemplo n.º 13
0
 public Wheels(string i_ManufacturerName, float i_CurrentAirPressure, float i_MaxAirPressure)
 {
     m_ManufacturerName = i_ManufacturerName;
     if (m_CurrentAirPressure < 0 || m_CurrentAirPressure > m_MaxAirPressure)
     {
         ValueOutOfRangeException value = new ValueOutOfRangeException(0, m_MaxAirPressure);
         throw value;
     }
     else
     {
         m_CurrentAirPressure = i_CurrentAirPressure;
     }
     m_MaxAirPressure = i_MaxAirPressure;
 }
Ejemplo n.º 14
0
        void Inflating(float i_AddAirPressure)
        {
            float newAirPressure = m_CurrentAirPressure + i_AddAirPressure;

            if (newAirPressure <= m_MaxAirPressure)
            {
                m_CurrentAirPressure = newAirPressure;
            }
            else
            {
                ValueOutOfRangeException value = new ValueOutOfRangeException(0, m_MaxAirPressure);
                throw value;
            }
        }
Ejemplo n.º 15
0
        public void FillFuel(eFuelType i_FuelType, float i_HowMuchToFill)
        {
            if (i_FuelType != r_FuelType)
            {
                ArgumentException typeMismatch = new ArgumentException();
                throw typeMismatch;
            }

            if (this.m_CurrentState + i_HowMuchToFill > this.r_MaxCapacity)
            {
                ValueOutOfRangeException valueOutOfRange = new ValueOutOfRangeException(this.r_MaxCapacity - this.m_CurrentState, 0f);
                throw valueOutOfRange;
            }

            this.m_CurrentState += i_HowMuchToFill;
        }
        public override void EnergyToVehicle(float i_AmountToAdd, EnergyOfEngine i_TypeOfEnergy)
        {
            if (i_TypeOfEnergy.CurrentAmountOfEnergy + i_AmountToAdd <= i_TypeOfEnergy.MaxAmountOfEnergy && i_AmountToAdd >= 0)
            {
                CurrentAmountOfEnergy += i_AmountToAdd;
                GarageManagment.IsMax  = false;
            }

            else
            {
                ValueOutOfRangeException ex = new ValueOutOfRangeException(0, i_TypeOfEnergy.MaxAmountOfEnergy, "You cant add this Amount Of Energy");
                GarageManagment.IsMax = true;
                string msg = ex.Message;
                Console.WriteLine(msg);
            }
        }
Ejemplo n.º 17
0
        // This method, is refueling the fuelSource, only if same fuel type and amount is legal.
        public void Refuel(float i_AmountToAdd, eFuelType i_FuelType)
        {
            if (this.r_FuelType != i_FuelType)
            {
                throw new ArgumentException();
            }

            if (this.MaxCapacity >= i_AmountToAdd + this.CurrAmount)
            {
                // Everything is fine.
                this.CurrAmount += i_AmountToAdd;
            }
            else
            {
                // Too big Amount.
                var voore = new ValueOutOfRangeException(0, this.MaxCapacity);
                voore.Source = this.GetType().Name;
                throw voore;
            }
        }
Ejemplo n.º 18
0
        public void UpdateColor(string i_Color)
        {
            if (int.TryParse(i_Color, out int res))
            {
                var first = Enum.GetValues(typeof(eColor)).Cast <eColor>().First();
                var last  = Enum.GetValues(typeof(eColor)).Cast <eColor>().Last();

                if (res >= (int)first && res <= (int)last)
                {
                    Enum.TryParse <eColor>(res.ToString(), out eColor color);
                    m_Color = color;
                }
                else
                {
                    ValueOutOfRangeException ec = new ValueOutOfRangeException(i_Color, (int)first, (int)last);
                }
            }
            else
            {
                throw new FormatException("Color is not supported");
            }
        }
Ejemplo n.º 19
0
        public static bool SpecValidation(eVehicleType i_VehicleType, Dictionary <string, string> i_SpecInfo)
        {
            bool          isValid = true;
            StringBuilder msg     = new StringBuilder();
            Exception     e       = new Exception();
            bool          isNum   = !true;

            switch (i_VehicleType)
            {
            case eVehicleType.Truck:
                i_SpecInfo.TryGetValue("Cargo Volume", out string cargoVolumeParse);
                i_SpecInfo.TryGetValue("Danguroes Matiriels", out string danguroesMatirielsParse);
                if (!float.TryParse(cargoVolumeParse, out float parse))
                {
                    isValid = !true;
                    msg.Append("Plase make sure you enter a valid number for Cargo volume. ");
                }
                if ((!(danguroesMatirielsParse.ToLower().Equals("false") || danguroesMatirielsParse.ToLower().Equals("true"))))
                {
                    isValid = !true;
                    msg.Append("Choose (Flase / True) for Danguroes Matiriels");
                }
                e = new FormatException(msg.ToString());
                break;

            case eVehicleType.ElectricCar:
            case eVehicleType.RegularCar:
                i_SpecInfo.TryGetValue("Door Color", out string doorColorParse);
                i_SpecInfo.TryGetValue("Number Of Doors", out string numberOfDoorsParse);
                bool isEnum = Enum.TryParse(doorColorParse, out eDoorsColor parseDoor);
                isNum = int.TryParse(doorColorParse, out int tryToParse);
                int numOfExeption = 0;
                if (!isEnum || isNum)
                {
                    isValid = !true;
                    msg.Append("please choose a valid color. ");
                    foreach (eDoorsColor type in Enum.GetValues(typeof(eDoorsColor)))
                    {
                        msg.Append(type.ToString() + " ");
                    }
                    numOfExeption++;
                    msg.Append(".");
                    e = new FormatException(msg.ToString());
                }
                if (!(int.TryParse(numberOfDoorsParse, out int numOfdoors)) || numOfdoors > 5 || numOfdoors < 2)
                {
                    isValid = !true;
                    e       = new ValueOutOfRangeException(2, 5);
                    numOfExeption++;
                    msg.Append(e.Message);
                }
                if (numOfExeption == 2)
                {
                    e = new FormatException(msg.ToString());
                }
                break;

            case eVehicleType.ElectricMotorcycle:
            case eVehicleType.RegularMotorcycle:
                i_SpecInfo.TryGetValue("License Type", out string licenseTypeParse);
                i_SpecInfo.TryGetValue("Engine Volume", out string ccParse);
                isNum = int.TryParse(licenseTypeParse, out int tryToParseLicense);
                if (!Enum.TryParse(licenseTypeParse, out eLicenseType parseLisence) || isNum)
                {
                    isValid = !true;
                    msg.Append("please enter your license type. ");
                    foreach (Motorcycle.eLicenseType type in Enum.GetValues(typeof(Motorcycle.eLicenseType)))
                    {
                        msg.Append(type.ToString() + " ");
                    }
                    msg.Append(".");
                }
                if (!int.TryParse(ccParse, out int tryToparse))
                {
                    isValid = !true;
                    msg.Append("Plase make sure you enter a valid number for engine volume. ");
                }
                e = new FormatException(msg.ToString());
                break;
            }
            if (!isValid)
            {
                throw e;
            }

            return(isValid);
        }