コード例 #1
0
        private void getMotorbikeProperties(ref Motorbike io_MotorbikeToUpdate)
        {
            bool isInputValid = false;
            int  userInput    = 0;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowScreen <Motorbike.eLicenseType>("Please enter the number of the desired licence type:");
                    userInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userInput, 1, Enum.GetValues(typeof(Motorbike.eLicenseType)).Length);
                    io_MotorbikeToUpdate.License = (Motorbike.eLicenseType)userInput;
                    OutputManager.ShowMessage("Please enter the motorbike engine volume.");
                    io_MotorbikeToUpdate.EngineVolume = InputManager.GetInputAndConvertToInt();
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
            }
        }
コード例 #2
0
        private void getCarProperties(ref Car io_CarToUpdate)
        {
            bool isInputValid = false;
            int  userInput    = 0;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the amount of doors in the car.");
                    io_CarToUpdate.AmountOfDoors = InputManager.GetInputAndConvertToInt();
                    OutputManager.ShowScreen <Car.eColor>("Please enter the number of the car color:");
                    userInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userInput, 1, Enum.GetValues(typeof(Car.eColor)).Length);
                    io_CarToUpdate.CarColor = (Car.eColor)userInput;
                    isInputValid            = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
            }
        }
コード例 #3
0
        private void rechargeFuel(string i_VehicleId, float i_FuelAmountToRecharge)
        {
            int fuelTypeInput = 0, enumLength = 0;

            enumLength = Enum.GetNames(typeof(FuelEngine.eFuelType)).Length;
            OutputManager.ShowScreen <FuelEngine.eFuelType>("Please enter the number for your desired fuel type:");
            fuelTypeInput = InputManager.GetInputAndConvertToInt();
            isInRange(fuelTypeInput, 1, enumLength);
            m_CurrentGarage.RechargeFuel(i_VehicleId, (FuelEngine.eFuelType)fuelTypeInput, i_FuelAmountToRecharge);
        }
コード例 #4
0
        private void rechargeVehicle()
        {
            bool          isInputValid = false;
            int           fuelTypeInput = 0, enumLength = 0;
            StringBuilder vehicleIdInput  = null;
            float         fuelAmountInput = 0;

            enumLength = Enum.GetNames(typeof(VehicleFactory.eEngineType)).Length;
            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter desired vehicle id, enter Q to go back.");
                    vehicleIdInput = InputManager.GetUserInput();
                    if (checkIfPressedQuit(vehicleIdInput))
                    {
                        break;
                    }
                    OutputManager.ShowScreen <VehicleFactory.eEngineType>("Enter the type of engine your vehicle has:");
                    fuelTypeInput = InputManager.GetInputAndConvertToInt();
                    isInRange(fuelTypeInput, 1, enumLength);
                    OutputManager.ShowMessage("Please enter the amount you wish to charge your vehicle:");
                    fuelAmountInput = InputManager.GetInputAndConvertToFloat();
                    if ((VehicleFactory.eEngineType)fuelTypeInput == VehicleFactory.eEngineType.Fuel)
                    {
                        rechargeFuel(vehicleIdInput.ToString(), fuelAmountInput);
                    }
                    else
                    {
                        rechargeElectric(vehicleIdInput.ToString(), fuelAmountInput);
                    }

                    OutputManager.ShowMessage("Successfully recharged.");
                    pressToContinue();
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
コード例 #5
0
        private void changeVehicleState()
        {
            int           stateChoiceInput = 0;
            bool          isInputValid     = false;
            StringBuilder vehicleIdInput   = null;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter desired vehicle's id, enter Q to go back.");
                    vehicleIdInput = InputManager.GetUserInput();
                    if (checkIfPressedQuit(vehicleIdInput))
                    {
                        break;
                    }
                    OutputManager.ShowScreen <StoredVehicle.eVehicleState>("Please enter the number of the desired vehicle's new state:");
                    stateChoiceInput = InputManager.GetInputAndConvertToInt();
                    isInRange(stateChoiceInput, 1, Enum.GetNames(typeof(StoredVehicle.eVehicleState)).Length);
                    m_CurrentGarage.ChangeVehicleState(vehicleIdInput.ToString(), (StoredVehicle.eVehicleState)stateChoiceInput);
                    OutputManager.ShowMessage("Successfuly changed the vehicle state.");
                    pressToContinue();
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
コード例 #6
0
        private Vehicle createNewVehicle()
        {
            bool    isInputValid     = false;
            int     userVehicleInput = 0;
            int     userEngineInput  = 0;
            Vehicle vehicleToCreate  = null;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowScreen <VehicleFactory.eVehicleType>("Please enter the number of the desired vehicle:");
                    userVehicleInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userVehicleInput, 1, Enum.GetValues(typeof(VehicleFactory.eVehicleType)).Length);
                    OutputManager.ShowScreen <VehicleFactory.eEngineType>("Please enter the number of the desired engine type:");
                    userEngineInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userEngineInput, 1, Enum.GetValues(typeof(VehicleFactory.eEngineType)).Length);
                    vehicleToCreate = VehicleFactory.CreateVehicle((VehicleFactory.eVehicleType)userVehicleInput,
                                                                   (VehicleFactory.eEngineType)userEngineInput);
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(ex.Message);
                    pressToContinue();
                }
            }

            return(vehicleToCreate);
        }