public override void UpdatePropertyByStringInputAndPropertyIndex(string i_UserInput, int PropertyIndex) { switch (PropertyIndex) { case (int)eCarProperties.CarColor: { eCarColor inputColor = (eCarColor)Enum.Parse(typeof(eCarColor), i_UserInput); if (!(Enum.IsDefined(typeof(eCarColor), i_UserInput))) { throw new Exception("This color doesn't exist, valid colors are: { Red, Silver, White, Black }"); } else { m_CarColor = inputColor; } break; } case (int)eCarProperties.NumberOfDoors: { eNumberOfDoors inputNumberOfDoors = (eNumberOfDoors)Enum.Parse(typeof(eNumberOfDoors), i_UserInput); if (!(Enum.IsDefined(typeof(eNumberOfDoors), int.Parse(i_UserInput)) || Enum.IsDefined(typeof(eNumberOfDoors), i_UserInput))) { throw new Exception("Invalid number of doors input, please enter a number between 2 and 5"); } else { m_NumberOfDoors = inputNumberOfDoors; } break; } } }
internal override void SetData(List <string> i_DataFromUser) { base.SetData(i_DataFromUser); int carColorAsInt = int.Parse(i_DataFromUser[k_CarColorLocation]); int numberOfDoors = int.Parse(i_DataFromUser[k_NumberOfDoorsLocation]); for (int i = 0; i < k_NumberOfWheels; i++) { m_WheelCollection[i].CurrentPressure = float.Parse(i_DataFromUser[k_WheelAirPressureLocation]); m_WheelCollection[i].Manufacturer = i_DataFromUser[k_WheelManufacturerLocation]; } if (!Enum.IsDefined(typeof(eCarColor), carColorAsInt)) { throw new FormatException("Car color must be Red, White, Black Or Silver only"); } if (!Enum.IsDefined(typeof(eNumberOfDoors), numberOfDoors)) { throw new FormatException("Number of doors must be Two, Three, Four or Five only"); } m_CarColor = (eCarColor)carColorAsInt; m_NumberOfDoors = (eNumberOfDoors)numberOfDoors; }
public static Car CreateCar(Energy i_Energy, Wheel[] i_Wheels, string i_LicenseNumber, string i_ModelName, eCarColor i_CarColor, eNumberOfDoors i_NumberOfDoors) { Car newCar = null; ElectricEnergy electricEnergy = i_Energy as ElectricEnergy; FuelBasedEnergy fuelBasedEnergy = i_Energy as FuelBasedEnergy; eVehicleType vehicleType = eVehicleType.Electric; if (electricEnergy != null) { isElectricCarParamsAreValid(i_Wheels, electricEnergy.MaxBatteryTime); } else if (fuelBasedEnergy != null) { isFuelBasedCarParamsAreValid(i_Wheels, fuelBasedEnergy.FuelType, fuelBasedEnergy.MaxFuelAmount); vehicleType = eVehicleType.FuelBased; } else { throw new ArgumentException("Not a valid Vehicle! Should be fuel based or electric based only."); } newCar = new Car(i_Energy, i_Wheels, i_CarColor, i_NumberOfDoors, i_ModelName, i_LicenseNumber, vehicleType); return(newCar); }
public override bool UpdateUniqueProperties(string i_Message, int i_PropertyNumber) { bool parseSucceed = false; if (i_PropertyNumber == (int)eCarProperties.Color) { int numberOfInputOptions = Enum.GetNames(typeof(eColorOfCar)).Length; int color = InputValidation.CorrectUserInput(i_Message, numberOfInputOptions); if (color != Constants.k_InValid) { m_Color = (eColorOfCar)color; parseSucceed = true; } } else if (i_PropertyNumber == (int)eCarProperties.NumberOfDoors) { int numberOfInputOptions = Enum.GetNames(typeof(eNumberOfDoors)).Length; int doorsNumber = InputValidation.CorrectUserInput(i_Message, numberOfInputOptions); if (doorsNumber != Constants.k_InValid) { m_NumberOfDoors = (eNumberOfDoors)doorsNumber; parseSucceed = true; } } return(parseSucceed); }
public Car( Owner i_Owner, string i_Model, string i_LicenceNumber, Tank i_Tank, Wheel[] i_Wheels, eColor i_Color, eNumberOfDoors i_NumberOfDoors) : base(i_Owner, i_Model, i_LicenceNumber, i_Tank, i_Wheels) { m_Color = i_Color; m_NumberOfDoors = i_NumberOfDoors; }
public override void InsertAnswer(string i_UserInput, int i_Index) { switch (i_Index) { case 1: if (i_UserInput == eEngineTypes.Gas.ToString()) { m_EnergySource = new GasEngine(eFuelType.Octan98, k_MaxGasEngine); } else { m_EnergySource = new ElectricEngine(k_MaxElectricalEngine); } break; case 2: m_NumberOfDoors = (eNumberOfDoors)Enum.Parse(typeof(eNumberOfDoors), i_UserInput); break; case 3: m_CarColor = (eCarColor)Enum.Parse(typeof(eCarColor), i_UserInput); break; case 4: m_EnergySource.CurrentEnergy = float.Parse(i_UserInput); break; default: break; } }
public Car(Energy i_Energy, Wheel[] i_Wheels, eCarColor i_CarColor, eNumberOfDoors i_NumberOfDoors, string i_ModelName, string i_LicenseNumber, eVehicleType i_VehicleType) : base(i_ModelName, i_LicenseNumber, i_Wheels, i_Energy, i_VehicleType) { m_CarColor = i_CarColor; m_NumberOfDoors = i_NumberOfDoors; }
public void CarVehicle(eColor i_Color, eNumberOfDoors i_NumberOfDoors) { m_Color = i_Color; m_NumberOfDoors = i_NumberOfDoors; m_CheckedList[3] = true; m_CheckedList[4] = true; }
public Car(eCarColors i_ChosenColor, eNumberOfDoors i_CarDoors, EnergyType o_TypeOfEnergy, string o_ModelName, string o_LicensePlate, OwnerDetails o_CarOwner, List <Wheel> o_Wheels) : base(o_ModelName, o_LicensePlate, o_CarOwner, o_Wheels) { m_CarColor = i_ChosenColor; m_NumberOfDoors = i_CarDoors; m_EnergyType = o_TypeOfEnergy; EnergyRatio = o_TypeOfEnergy.CalculateRatio(); }
internal Car(string i_m_ModelName, string i_LicenseNumber, List <Wheels> i_ListOfWheels, EnergyType i_EnergyType, eNumberOfDoors i_NumberOfDoors, eCarColor i_CarColor) : base(i_m_ModelName, i_LicenseNumber, i_ListOfWheels, i_EnergyType) { this.r_CarColor = i_CarColor; this.r_NumberOfDoors = i_NumberOfDoors; }
public Car(string i_Manufacturer, string i_PlateLicenseNumber, float i_RemainingEnergy, EnergySource.eEnergySourceType i_EnergyType, string i_WheelsManufacturName, float i_CurrentWheelsAirPressure) : base(i_Manufacturer, i_PlateLicenseNumber, i_RemainingEnergy, k_NumberOfWheels, k_MaxAirPressure, i_EnergyType, i_WheelsManufacturName, i_CurrentWheelsAirPressure) { m_CarColor = new eCarColor(); m_NumberOfDoors = new eNumberOfDoors(); }
public ElectricCar( OwnerInfo i_Owner, string i_ModelName, string i_LicenseNumber, eColors i_Color, eNumberOfDoors i_NumOfDoors) : base(i_Owner, i_ModelName, i_LicenseNumber, k_MaxBatteryCapacity, i_Color, i_NumOfDoors, eEngineTypes.Electric) { }
public FuelCar( OwnerInfo i_Owner, string i_ModelName, string i_LicenseNumber, eColors i_Color, eNumberOfDoors i_NumOfDoors, eFuelTypes i_FuelType) : base(i_Owner, i_ModelName, i_LicenseNumber, k_FuelTankCapacity, i_Color, i_NumOfDoors, eEngineTypes.Fuel) { r_FuelType = i_FuelType; }
public Car( string i_CarModel, string i_LicenseNumber, float i_EnergyPercent, List <Wheel> i_Wheels, PowerUsage i_PowerSource, eCarColor i_CarColor, eNumberOfDoors i_NumberOfDoors) : base(i_CarModel, i_LicenseNumber, i_EnergyPercent, i_Wheels, i_PowerSource) { m_CarColor = i_CarColor; m_NumberOfDoors = i_NumberOfDoors; }
public Car( OwnerInfo i_Owner, string i_ModelName, string i_LicenseNumber, float i_MaxEnergyCapacity, eColors i_Color, eNumberOfDoors i_NumOfDoors, eEngineTypes i_EngineType) : base(i_Owner, i_ModelName, i_LicenseNumber, i_MaxEnergyCapacity, k_MaxAirPressure, k_NumberOfWheels, i_EngineType) { r_Color = i_Color; r_NumberOfDoors = i_NumOfDoors; }
public override void SetVehicleData() { m_CarColor = (eCarColor)Enum.Parse(typeof(eCarColor), m_GarageVehicleUtils.UserInput[0]); m_NumberOfDoors = (eNumberOfDoors)Enum.Parse(typeof(eNumberOfDoors), m_GarageVehicleUtils.UserInput[1]); if (!Enum.IsDefined(typeof(eCarColor), m_CarColor)) { throw new FormatException("Wrong Color of car, please select from the list"); } if (!Enum.IsDefined(typeof(eNumberOfDoors), m_NumberOfDoors)) { throw new FormatException("Wrong Number of door, please select from the list"); } }
private eNumberOfDoors inputNumberOfDoors() { Console.WriteLine(string.Format( @"- Choose the number of doors you want - 2 -> Press 1 3 -> Press 2 4 -> Press 3 5 -> Press any other key")); string choice = Console.ReadLine(); eNumberOfDoors numberOfDoors = findNumberOfDoors(choice); return(numberOfDoors); }
public override void SetVehicleDetails(Dictionary <string, object> i_VehilceInfo) { base.SetVehicleDetails(i_VehilceInfo); m_CarColor = (eCarColor)i_VehilceInfo["CarColor"]; m_NumberOfDoors = (eNumberOfDoors)i_VehilceInfo["CarDoors"]; if (EnergyType == eEnergyTypes.Electric) { m_VehicleEnergy = new Electric((float)i_VehilceInfo["RemainingEnergy"], (float)i_VehilceInfo["MaximumEnergyCapacity"]); } else { m_VehicleEnergy = new Fuel((float)i_VehilceInfo["RemainingEnergy"], (float)i_VehilceInfo["MaximumEnergyCapacity"], (eEnergyTypes)i_VehilceInfo["EnergyType"]); } }
public void CheckNumberOfDoorsAndUpdate(string i_input) // this function check the number of doors input and updeate the data member { try { m_numberOfDoors = (eNumberOfDoors)Enum.Parse(typeof(eNumberOfDoors), i_input); // if the number of doors input from the user is a legal input - updeate the data member if (m_numberOfDoors < eNumberOfDoors.TWO || m_numberOfDoors > eNumberOfDoors.FIVE) { throw new ArgumentException(); } } catch (ArgumentException Ex) { throw new ArgumentException("You have to choose one of the following: <TWO, TREE, FOUR, FIVE>"); } }
public void SetNumberOfDoors(string i_NumerOfEnumDoors) { int actionNumber; bool isValidAction; actionNumber = int.Parse(i_NumerOfEnumDoors); isValidAction = Enum.IsDefined(typeof(eNumberOfDoors), actionNumber); if (!isValidAction) { throw new ArgumentException("Invalid input"); } else { m_NumberOfDoors = (eNumberOfDoors)actionNumber; } }
public Car( VehicleFactory.eVehicleType i_VehicleType, string i_ModelName, string i_LicenseNumber, Tire[] i_Tires, Engine i_Engine, float i_EnergyPercentageLeft, string i_TireManufactureName, float i_TireCurrentAirPressure, eCarColors i_CarColor, eNumberOfDoors i_NumOfDoors) : base(i_VehicleType, i_ModelName, i_LicenseNumber, i_Tires, i_Engine, i_EnergyPercentageLeft, i_TireManufactureName, k_MaxAirPressure, i_TireCurrentAirPressure) { r_CarColor = i_CarColor; r_NumOfDoors = i_NumOfDoors; }
public override bool SetSpecialVariables(int i_NumberOfQuestion, string i_ValueOfVariable) { const int k_MinimumDoorsValue = 2; int indexOfValue; int maxNumberOfColors = Enum.GetValues(typeof(eColorOfCar)).Length; int maxNumberOfDoors = Enum.GetValues(typeof(eNumberOfDoors)).Length - 1 + k_MinimumDoorsValue; if (i_NumberOfQuestion == 1) { if (int.TryParse(i_ValueOfVariable, out indexOfValue)) { if (indexOfValue >= k_MinimumEnumValue && indexOfValue <= maxNumberOfColors) { m_ColorOfCar = (eColorOfCar)Enum.Parse(typeof(eColorOfCar), i_ValueOfVariable); } else { throw new ValueOutOfRangeException(k_MinimumEnumValue, maxNumberOfColors); } } else { throw new FormatException(); } } else { if (int.TryParse(i_ValueOfVariable, out indexOfValue)) { if (indexOfValue >= k_MinimumDoorsValue && indexOfValue <= maxNumberOfDoors) { m_NumberOfDoors = (eNumberOfDoors)Enum.Parse(typeof(eNumberOfDoors), i_ValueOfVariable); } else { throw new ValueOutOfRangeException(k_MinimumEnumValue, maxNumberOfDoors); } } else { throw new FormatException(); } } return(true); }
public Car( ePossibleCarColors i_CarColor, eNumberOfDoors i_NumberOfDoorsInCar, string i_ModelName, string i_LicenceNumber, float i_PercentOfEnergyLeft, Energy i_EnergyType, List <Wheel> i_Wheels) : base( i_ModelName, i_LicenceNumber, i_PercentOfEnergyLeft, i_EnergyType, i_Wheels) { m_CarColor = i_CarColor; m_NumberOfDoorsInCar = i_NumberOfDoorsInCar; }
private void putNewCarInGarage(string i_LicenseNumber, string i_ModelName, float i_PercentageOfEnergyLeft, VehicleInGarage i_VehicleInGarage, List <Wheel> i_Wheels) { eCarColor carColor = inputCarColor(); eNumberOfDoors numberOfDoors = inputNumberOfDoors(); Console.WriteLine(string.Format(@"choose the type of vehicle you want: for fuel engine car - press 1 for electric engine car - press any other key")); string choice = Console.ReadLine(); if (choice == "1") { putNewFuelCarInGarage(i_LicenseNumber, i_ModelName, i_PercentageOfEnergyLeft, carColor, numberOfDoors, i_VehicleInGarage, i_Wheels); } else { putNewElectricCarInGarage(i_LicenseNumber, i_ModelName, i_PercentageOfEnergyLeft, carColor, numberOfDoors, i_VehicleInGarage, i_Wheels); } }
private void getCarNumberOfDoors() { Console.Write("Please insert the number of Car doors <2-5>: "); string carNumberOfDoors = Console.ReadLine(); try { m_CarNumberOfDoors = (eNumberOfDoors)Enum.Parse(typeof(eNumberOfDoors), carNumberOfDoors); if (!Enum.IsDefined(typeof(eNumberOfDoors), m_CarNumberOfDoors)) { throw new FormatException($"'{carNumberOfDoors}' is not a valid input!"); } } catch (ArgumentException) { throw new FormatException($"'{carNumberOfDoors}' is not a valid input!"); } m_IsInputValid = true; }
public override void UpdateProperties(List <string> i_UserDialogueInputsList) { base.UpdateProperties(i_UserDialogueInputsList); float currentWheelAirPressure = float.Parse( i_UserDialogueInputsList[(int)eVehicleUserDialogueListIndex.CurrentWheelAirPressure]); int numberOfDoors = int.Parse(i_UserDialogueInputsList[(int)eCarUserDialogueListIndex.NumberOfDoors]); int carColor = int.Parse(i_UserDialogueInputsList[(int)eCarUserDialogueListIndex.Color]); GasEngine gasEngine = m_Engine as GasEngine; if (gasEngine != null) { gasEngine.GasType = GasEngine.eGasType.Octan96; } InitializeWheelsList( eNumberOfWheels.Car, i_UserDialogueInputsList[(int)eVehicleUserDialogueListIndex.WheelManufacturer], currentWheelAirPressure, Wheel.eMaxAirPressure.Car); m_NumberOfDoors = (eNumberOfDoors)numberOfDoors; m_CarColor = (eColor)carColor; }
public override void SetListOfMembersToIntialize(int i_MemberIndexInEnum, string i_MemberValue) { eCarMembersToInitialize vehicleMember = (eCarMembersToInitialize)i_MemberIndexInEnum; int memberValue; switch (vehicleMember) { case eCarMembersToInitialize.Model: { m_ModelName = i_MemberValue; break; } case eCarMembersToInitialize.CarColor: { if (checkIfEnumContainThisChoice <eCarColor>(i_MemberValue, out memberValue)) { m_CarColor = (eCarColor)memberValue; } else { if (int.TryParse(i_MemberValue, out memberValue)) { if (Enum.IsDefined(typeof(eCarColor), memberValue)) { m_CarColor = (eCarColor)memberValue; } else { throw new ArgumentException("There isn't such color."); } } else { throw new FormatException("The value is invalid."); } } break; } case eCarMembersToInitialize.NumberOfDoors: { if (checkIfEnumContainThisChoice <eNumberOfDoors>(i_MemberValue, out memberValue)) { m_NumberOfDoors = (eNumberOfDoors)memberValue; } else { if (int.TryParse(i_MemberValue, out memberValue)) { if (Enum.IsDefined(typeof(eNumberOfDoors), memberValue)) { m_NumberOfDoors = (eNumberOfDoors)memberValue; } else { throw new ArgumentException("There isn't such option of doors."); } } else { throw new FormatException("The value is invalid."); } } break; } } }
public GasCar(Owner i_Owner, string i_Model, string i_LicenceNumber, GasTank i_GasTank, Wheel[] i_Wheels, eColor i_Color, eNumberOfDoors i_NumberOfDoors) : base(i_Owner, i_Model, i_LicenceNumber, i_GasTank, i_Wheels, i_Color, i_NumberOfDoors) { }
public ElectricCar CreateNewElectricCar(ElectricEngine i_ElectriclEngine, eNumberOfDoors i_NumberOfDoors, eCarColor i_CarColor, string i_ModelName, string i_LicenseNumber, float i_ThePercentageOfEnergyLeft, List <Wheel> i_Wheels) { ElectricCar electricCar = new ElectricCar(i_ElectriclEngine, i_NumberOfDoors, i_CarColor, i_ModelName, i_LicenseNumber, i_ThePercentageOfEnergyLeft, i_Wheels); return(electricCar); }
public FuelCar CreateNewFuelCar(FuelEngine i_FuelVehicle, eNumberOfDoors i_NumberOfDoors, eCarColor i_CarColor, string i_ModelName, string i_LicenseNumber, float i_ThePercentageOfEnergyLeft, List <Wheel> i_Wheels) { FuelCar fuelCar = new FuelCar(i_FuelVehicle, i_NumberOfDoors, i_CarColor, i_ModelName, i_LicenseNumber, i_ThePercentageOfEnergyLeft, i_Wheels); return(fuelCar); }