private void getAndCheckTheUserOperationChoise() { const int k_FirstOptionValueInMenu = 1; const bool v_BeingInTheVehicleGarage = true; string strUserOperationChoiseInGarage; int lastOptionValueInMenu = Enum.GetNames(typeof(eUserInputOperationChoise)).Length; while (m_ContinueBeingInTheVehicleGarage = v_BeingInTheVehicleGarage) { try { strUserOperationChoiseInGarage = Console.ReadLine(); // Check the user enter correct number CheckInputsFromUserCorrect.CheckIntegerInputFromUserIsInCorrectRange(strUserOperationChoiseInGarage, k_FirstOptionValueInMenu, lastOptionValueInMenu); doTheUserSelectedOperation(strUserOperationChoiseInGarage); displayTheGarageMenuOptionsToUser(); } catch (FormatException formatEx) { Console.WriteLine(formatEx.Message); } catch (ArgumentException argumentEx) { Console.WriteLine(argumentEx.Message); } catch (ValueOutOfRangeException valueOutOfRangeEx) { Console.WriteLine(valueOutOfRangeEx.Message); } } }
private VehicleCreation.eVehicleTypes getVehicleType() { const bool v_CorrectInput = true; bool userEnteredCorrectInput = true; string strUserVehicleTypeChoise; VehicleCreation.eVehicleTypes vehicleType = VehicleCreation.eVehicleTypes.ElectricCar; string strDisplayMenuToUser = string.Format(@"Please choose one of the vehicle types : 1. Gas MotorCycle 2. Electric Motorcycle 3. Gas Car 4. Electric Car 5. Truck"); userEnteredCorrectInput = !userEnteredCorrectInput; while (userEnteredCorrectInput != v_CorrectInput) { try { Console.WriteLine(strDisplayMenuToUser); strUserVehicleTypeChoise = Console.ReadLine(); // Check the user enter correct number CheckInputsFromUserCorrect.CheckIntegerInputFromUserIsInCorrectRange(strUserVehicleTypeChoise, 1, Enum.GetNames(typeof(VehicleCreation.eVehicleTypes)).Length); // Convert user type choise to enum vehicleType = (VehicleCreation.eVehicleTypes) int.Parse(strUserVehicleTypeChoise); userEnteredCorrectInput = v_CorrectInput; } catch (FormatException formatEx) { Console.WriteLine(formatEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ArgumentException argumentEx) { Console.WriteLine(argumentEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ValueOutOfRangeException valueOutOfRangeEx) { Console.WriteLine(valueOutOfRangeEx.Message); userEnteredCorrectInput = !v_CorrectInput; } } return(vehicleType); }
private void chooseFuelTypeToFill(out string o_StrFuelTypeChoise) { const bool v_CorrectInput = true; bool userEnteredCorrectInput = true; o_StrFuelTypeChoise = null; userEnteredCorrectInput = !userEnteredCorrectInput; while (userEnteredCorrectInput != v_CorrectInput) { try { Console.WriteLine(); string strfuelTypeMsg = string.Format( @"Please choose type of gasoline : 1. Octan95 2. Octan96 3. Octan98 4. Soler"); Console.WriteLine(strfuelTypeMsg); o_StrFuelTypeChoise = Console.ReadLine(); // Check it's a good input fuel choise CheckInputsFromUserCorrect.CheckIntegerInputFromUserIsInCorrectRange(o_StrFuelTypeChoise, 1, Enum.GetNames(typeof(GasolineVehicle.eFuelTypes)).Length); userEnteredCorrectInput = v_CorrectInput; } catch (FormatException formatEx) { Console.WriteLine(formatEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ArgumentException argumentEx) { Console.WriteLine(argumentEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ValueOutOfRangeException valueOutOfRangeEx) { Console.WriteLine(valueOutOfRangeEx.Message); userEnteredCorrectInput = !v_CorrectInput; } } }
private void getColorForCar(out string o_FirstVehicleValue) { const bool v_CorrectInput = true; bool userEnteredCorrectInput = true; o_FirstVehicleValue = null; userEnteredCorrectInput = !userEnteredCorrectInput; string strFirstDisplayMenuToUser = string.Format(@"Please choose color of car : 1. Red 2. Blue 3. Black 4. Grey "); while (userEnteredCorrectInput != v_CorrectInput) { try { // Get the first value Console.WriteLine(strFirstDisplayMenuToUser); o_FirstVehicleValue = Console.ReadLine(); // Check the user enter correct number CheckInputsFromUserCorrect.CheckIntegerInputFromUserIsInCorrectRange(o_FirstVehicleValue, 1, Enum.GetNames(typeof(Car.eCarColor)).Length); userEnteredCorrectInput = v_CorrectInput; } catch (FormatException formatEx) { Console.WriteLine(formatEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ArgumentException argumentEx) { Console.WriteLine(argumentEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ValueOutOfRangeException valueOutOfRangeEx) { Console.WriteLine(valueOutOfRangeEx.Message); userEnteredCorrectInput = !v_CorrectInput; } } }
private void getTheVehicleStatusYouWantToChange(out string o_VehicleStatusYouWantToChange) { const bool v_CorrectInput = true; bool userEnteredCorrectInput = true; o_VehicleStatusYouWantToChange = null; userEnteredCorrectInput = !userEnteredCorrectInput; while (userEnteredCorrectInput != v_CorrectInput) { try { Console.WriteLine(); string vehicleNewStatusStr = string.Format(@"Please enter one of this options to change to : 1.InFix 2.Fixed 3.Paid"); Console.WriteLine(vehicleNewStatusStr); o_VehicleStatusYouWantToChange = Console.ReadLine(); // Check it's a good input licence number CheckInputsFromUserCorrect.CheckIntegerInputFromUserIsInCorrectRange(o_VehicleStatusYouWantToChange, 1, Enum.GetNames(typeof(Vehicle.eVehicleStatusInGarage)).Length); userEnteredCorrectInput = v_CorrectInput; } catch (FormatException formatEx) { Console.WriteLine(formatEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ArgumentException argumentEx) { Console.WriteLine(argumentEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ValueOutOfRangeException valueOutOfRangeEx) { Console.WriteLine(valueOutOfRangeEx.Message); userEnteredCorrectInput = !v_CorrectInput; } } }
private void getLicenceTypeForMotorCycle(out string o_FirstVehicleValue) { const bool v_CorrectInput = true; bool userEnteredCorrectInput = true; string strDisplayMenuToUser = string.Format(@"Please choose Licence type of motorCycle : 1. A 2. A1 3. A2 4. B "); o_FirstVehicleValue = null; userEnteredCorrectInput = !userEnteredCorrectInput; while (userEnteredCorrectInput != v_CorrectInput) { try { // Get the first value Console.WriteLine(strDisplayMenuToUser); o_FirstVehicleValue = Console.ReadLine(); // Check the user enter correct number CheckInputsFromUserCorrect.CheckIntegerInputFromUserIsInCorrectRange(o_FirstVehicleValue, 1, Enum.GetNames(typeof(MotorCycle.eLicenceType)).Length); userEnteredCorrectInput = v_CorrectInput; } catch (FormatException formatEx) { Console.WriteLine(formatEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ArgumentException argumentEx) { Console.WriteLine(argumentEx.Message); userEnteredCorrectInput = !v_CorrectInput; } catch (ValueOutOfRangeException valueOutOfRangeEx) { Console.WriteLine(valueOutOfRangeEx.Message); userEnteredCorrectInput = !v_CorrectInput; } } }