예제 #1
0
        private Vehicle EnterNewVehicle(string i_LicensePlate, out GarageManager.eSupportedVehciles o_ClientVehicle)
        {
            string clientVehicleOptionString = string.Empty;

            o_ClientVehicle = 0;
            string carDetailsInput      = string.Empty;
            bool   isValidVehicleOption = false;

            OutputToConsole(
                @"please enter a number that matches your vehicle type from the given options
  in order to enter it to the garage:
1. Electric Bike
2. Electric Car
3. Fueled Bike
4. Fueled Car
5. Truck");
            while (!isValidVehicleOption)
            {
                try
                {
                    clientVehicleOptionString = InputFromConsole();
                    o_ClientVehicle           = UserInputExceptions.ParseVehicleTypeInput(clientVehicleOptionString, this.m_GarageManager);
                    isValidVehicleOption      = true;
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            return(enterNewVehicleMembers(o_ClientVehicle));
        }
예제 #2
0
 public void AddVehicleToClient(
     Vehicle i_Vehicle,
     eVehicleStatus i_Status,
     GarageManager.eSupportedVehciles i_SupportedVehicle,
     string i_LicensePlate)
 {
     m_Vehicles.Add(i_LicensePlate, new SingleVehicleInfo(i_Vehicle, Type.GetType(GarageManager.k_NameSpace + i_SupportedVehicle.ToString()), i_Status));
 }
예제 #3
0
        public static Vehicle CreateVehicle(GarageManager.eSupportedVehciles i_SupportedVehicle, object[] i_InputParameters, Vehicle i_CurrentVehicleObject)
        {
            Type       typeOfVehicle   = Type.GetType("Ex03.GarageLogic." + i_SupportedVehicle.ToString());
            MethodInfo constructMethod = typeOfVehicle.GetMethod("Construct");

            i_CurrentVehicleObject = constructMethod.Invoke(i_CurrentVehicleObject, i_InputParameters) as Vehicle;
            return(i_CurrentVehicleObject);
        }
예제 #4
0
 public GarageClient(
     string i_ClientName,
     string i_ClientPhone,
     Vehicle i_Vehicle,
     eVehicleStatus i_Status,
     GarageManager.eSupportedVehciles i_SupportedVehicle)
 {
     m_ClientName  = i_ClientName;
     m_ClientPhone = i_ClientPhone;
     m_Vehicles    = new Dictionary <string, SingleVehicleInfo>();
     AddVehicleToClient(i_Vehicle, i_Status, i_SupportedVehicle, i_Vehicle.GetLicensePlate());
 }
        public static float ParseFuelOrChargeAmount(GarageManager.eSupportedVehciles i_Vehicle, string i_Input)
        {
            float floatInput = ParseFloatInput(i_Input);

            switch (i_Vehicle)
            {
            case GarageManager.eSupportedVehciles.ElectricBike:
                if (floatInput > 1.9f || floatInput < 0)
                {
                    throw new GarageLogic.ValueOutOfRangeException(0, 1.9f);
                }

                break;

            case GarageManager.eSupportedVehciles.ElectricCar:
                if (floatInput > 3.3f || floatInput < 0)
                {
                    throw new GarageLogic.ValueOutOfRangeException(0, 3.3f);
                }

                break;

            case GarageManager.eSupportedVehciles.FueledBike:
                if (floatInput > 7.2f || floatInput < 0)
                {
                    throw new GarageLogic.ValueOutOfRangeException(0, 7.2f);
                }

                break;

            case GarageManager.eSupportedVehciles.FueledCar:
                if (floatInput > 38f || floatInput < 0)
                {
                    throw new GarageLogic.ValueOutOfRangeException(0, 38f);
                }

                break;

            case GarageManager.eSupportedVehciles.Truck:
                if (floatInput > 135f || floatInput < 0)
                {
                    throw new GarageLogic.ValueOutOfRangeException(0, 135f);
                }

                break;

            default:
                break;
            }

            return(floatInput);
        }
        public static GarageManager.eSupportedVehciles ParseVehicleTypeInput(string i_Input, GarageManager i_GarageManager)
        {
            GarageManager.eSupportedVehciles vehicleTypeInput = 0;
            GarageManager.eSupportedVehciles typeOfInput      = 0;
            try
            {
                typeOfInput = (GarageManager.eSupportedVehciles)Enum.Parse(typeof(GarageManager.eSupportedVehciles), i_Input);
            }
            catch
            {
                throw new FormatException("Invalid input, must be a valid vehicle");
            }

            switch (typeOfInput)
            {
            case GarageManager.eSupportedVehciles.ElectricBike:
                vehicleTypeInput = GarageManager.eSupportedVehciles.ElectricBike;
                break;

            case GarageManager.eSupportedVehciles.ElectricCar:
                vehicleTypeInput = GarageManager.eSupportedVehciles.ElectricCar;
                break;

            case GarageManager.eSupportedVehciles.FueledBike:
                vehicleTypeInput = GarageManager.eSupportedVehciles.FueledBike;
                break;

            case GarageManager.eSupportedVehciles.FueledCar:
                vehicleTypeInput = GarageManager.eSupportedVehciles.FueledCar;
                break;

            case GarageManager.eSupportedVehciles.Truck:
                vehicleTypeInput = GarageManager.eSupportedVehciles.Truck;
                break;

            default:
                throw new FormatException("Invalid input, you must enter a number (1-5) represting a supported vehicle");
            }

            return(vehicleTypeInput);
        }
        public static float ParseTirePressure(GarageManager.eSupportedVehciles i_Vehicle, string i_Input)
        {
            float floatInput = ParseFloatInput(i_Input);

            if (i_Vehicle == GarageManager.eSupportedVehciles.Truck)
            {
                if (floatInput > 28 || floatInput < 0)
                {
                    throw new ValueOutOfRangeException(0, 28);
                }
            }
            else
            {
                if (floatInput > 31 || floatInput < 0)
                {
                    throw new ValueOutOfRangeException(0, 31);
                }
            }

            return(floatInput);
        }
예제 #8
0
        private float[] enterNewTiresArray(int i_NumOfWheels, GarageManager.eSupportedVehciles i_Vehicle)
        {
            float[] tiresArray  = new float[i_NumOfWheels];
            string  memberInput = string.Empty;
            float   o_Tire;
            bool    isValid = false;

            for (int i = 0; i < tiresArray.Length; i++)
            {
                OutputToConsole(string.Format("enter pressure of tire No. {0}:", i + 1));
                isValid = false;
                while (!isValid)
                {
                    memberInput = InputFromConsole();
                    if (float.TryParse(memberInput, out o_Tire))
                    {
                        try
                        {
                            UserInputExceptions.ParseTirePressure(i_Vehicle, memberInput);
                            tiresArray[i] = o_Tire;
                            isValid       = true;
                        }
                        catch (ValueOutOfRangeException e)
                        {
                            OutputToConsole(string.Format("{0} Only {1} - {2}{3}", e.Message, e.MinValue, e.MaxValue, Environment.NewLine));
                        }
                    }
                    else
                    {
                        OutputToConsole("wheel pressure must be a positive float number");
                    }
                }
            }

            return(tiresArray);
        }
예제 #9
0
 public Vehicle CallCreateVehicle(GarageManager.eSupportedVehciles i_SupportedVehicle, object[] i_InputParameters)
 {
     return(VehicleFactory.CreateVehicle(i_SupportedVehicle, i_InputParameters, this.m_CurrentVehicleConstruction));
 }
예제 #10
0
        private Vehicle enterNewVehicleMembers(GarageManager.eSupportedVehciles i_SupportedVehicle)
        {
            List <MemberTranslator> vehicleMembersList   = null;
            List <object>           membersFromInputList = new List <object>();
            Vehicle vehicleInstance = null;

            object[] vehicleMembersArray = null;
            bool     isMemberValid       = false;
            string   memberInput         = string.Empty;
            int      o_NumOfTires        = 0;
            string   o_ResultMembers     = string.Empty;
            object   parsedMemberInput   = null;

            vehicleMembersList = this.m_GarageManager.GetVehicleMembers(i_SupportedVehicle);

            foreach (MemberTranslator param in vehicleMembersList)
            {
                ///filling the tires require a different method to form a "tires array"
                if (param.m_MemberName.Equals("m_Wheels"))
                {
                    if (NumOfWheelsPerVehicle.TryGetValue(i_SupportedVehicle, out o_NumOfTires))
                    {
                        parsedMemberInput = enterNewTiresArray(o_NumOfTires, i_SupportedVehicle);
                        isMemberValid     = true;
                    }

                    ///for all the rest of the members
                }
                else if (param.m_MemberName == "m_LicensePlate")
                {
                    parsedMemberInput = m_CurrentVehicleLicensePlate;
                    isMemberValid     = true;
                }
                else if (param.m_MemberName == "m_CurrentFuelAmount" || param.m_MemberName == "m_ChargeTimeLeft")
                {
                    isMemberValid = false;
                    OutputToConsole(string.Format("enter {0}:", param.m_MemberTranslation));
                    while (!isMemberValid)
                    {
                        try
                        {
                            parsedMemberInput = UserInputExceptions.ParseFuelOrChargeAmount(i_SupportedVehicle, InputFromConsole());
                            isMemberValid     = true;
                        }
                        catch (ValueOutOfRangeException e)
                        {
                            OutputToConsole(string.Format("{0} Only {1} - {2}{3}", e.Message, e.MinValue, e.MaxValue, Environment.NewLine));
                        }
                        catch (Exception e)
                        {
                            OutputToConsole(e.Message);
                        }
                    }
                }
                else
                {
                    OutputToConsole(string.Format("enter {0}:", param.m_MemberTranslation));
                    isMemberValid = false;
                }

                while (!isMemberValid)
                {
                    try
                    {
                        memberInput       = InputFromConsole();
                        parsedMemberInput = UserInputExceptions.ExceptionParser(memberInput, param.m_MemberType);
                        isMemberValid     = true;
                    }
                    catch (Exception e)
                    {
                        OutputToConsole(e.Message);
                    }
                }

                membersFromInputList.Add(parsedMemberInput);
            }

            ///create a new vehicle instance with all relevant params for the specific car type given
            vehicleMembersArray = membersFromInputList.ToArray();
            vehicleInstance     = this.m_GarageManager.CallCreateVehicle(i_SupportedVehicle, vehicleMembersArray);
            return(vehicleInstance);
        }