Beispiel #1
0
        private void getTruckProperties(ref Truck io_TruckToUpdate)
        {
            bool isInputValid = false;
            int  userInput    = 0;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the truck cargo volume.");
                    io_TruckToUpdate.CargoVolume = InputManager.GetInputAndConvertToInt();
                    OutputManager.ShowMessage(@"Is the truck containing dangerous products?
1. Yes
2. No");
                    userInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userInput, 1, 2);
                    io_TruckToUpdate.IsContainingDangerousProducts = userInput == 1;
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Beispiel #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();
                }
            }
        }
Beispiel #3
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();
                }
            }
        }
Beispiel #4
0
        private void showVehicleDetails()
        {
            bool          isInputValid   = false;
            StringBuilder vehicleIdInput = null;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the desired vehicle id, enter Q to go back.");
                    vehicleIdInput = InputManager.GetUserInput();
                    if (checkIfPressedQuit(vehicleIdInput))
                    {
                        break;
                    }
                    OutputManager.ShowMessage(m_CurrentGarage.GetStoredVehicleDetailsString(vehicleIdInput.ToString()));
                    pressToContinue();
                    isInputValid = true;
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Beispiel #5
0
        private void inflateAirInAllWheels()
        {
            bool          isInputValid   = false;
            StringBuilder vehicleIdInput = null;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the desired vehicle id, enter Q to go back.");
                    vehicleIdInput = InputManager.GetUserInput();
                    if (checkIfPressedQuit(vehicleIdInput))
                    {
                        break;
                    }
                    m_CurrentGarage.InflateVehicleWheelsToMaximumCapacity(vehicleIdInput.ToString());
                    OutputManager.ShowMessage("Successully inflated all the wheels.");
                    pressToContinue();
                    isInputValid = true;
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Beispiel #6
0
        private void showFilteredId()
        {
            int           userChoice, enumLength;
            StringBuilder stringOfIdToPrint;
            bool          isInputValid = false;

            enumLength = Enum.GetNames(typeof(StoredVehicle.eVehicleState)).Length;
            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowFilterByVehicleStateScreen();
                    userChoice = InputManager.GetInputAndConvertToInt();
                    isInRange(userChoice, 1, enumLength + 1);
                    stringOfIdToPrint = getFilteredVehicleId(userChoice);
                    OutputManager.ShowMessage(stringOfIdToPrint.ToString());
                    pressToContinue();
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Beispiel #7
0
        private void storeNewVehicleInGarage()
        {
            VehicleOwner newOwnerToStore   = new VehicleOwner();
            Vehicle      newVehicleToStore = null;

            newOwnerToStore   = createNewVehicleOwner();
            newVehicleToStore = createNewVehicle();
            changeVehicleDetails(ref newVehicleToStore);
            m_CurrentGarage.StoreVehicle(newVehicleToStore, newOwnerToStore);
            OutputManager.ShowMessage("Successfully entered to garage.");
            pressToContinue();
        }
Beispiel #8
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();
                }
            }
        }
Beispiel #9
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();
                }
            }
        }
Beispiel #10
0
        private void getVehicleProperties(ref Vehicle io_NewVehicleToUpdate)
        {
            bool isInputValid = false;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the vehicle license number");
                    io_NewVehicleToUpdate.ID = InputManager.GetUserInput().ToString();
                    OutputManager.ShowMessage("Please enter the vehicle model name");
                    io_NewVehicleToUpdate.ModelName = InputManager.GetUserInput().ToString();
                    OutputManager.ShowMessage("Please enter current engine energy.");
                    io_NewVehicleToUpdate.Engine.CurrentEnergy = InputManager.GetInputAndConvertToFloat();
                    io_NewVehicleToUpdate.calculateCurrentEnergyPercent();
                    OutputManager.ShowMessage("Please enter the wheels manufacturer.");
                    io_NewVehicleToUpdate.SetWheelsManufacturerName(InputManager.GetUserInput().ToString());
                    OutputManager.ShowMessage("Please enter the current wheels' air pressure.");
                    io_NewVehicleToUpdate.SetWheelsAirPressure(InputManager.GetInputAndConvertToFloat());
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Beispiel #11
0
        private VehicleOwner createNewVehicleOwner()
        {
            VehicleOwner newVehicleOwner = new VehicleOwner();
            bool         isInputValid    = false;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the owner name:");
                    newVehicleOwner.Name = InputManager.GetUserInput().ToString();
                    OutputManager.ShowMessage("Please enter the owners phone number:");
                    newVehicleOwner.PhoneNumber = InputManager.GetUserInput().ToString();
                    isInputValid = true;
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }

            return(newVehicleOwner);
        }