示例#1
0
        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;
            }
            }
        }
示例#2
0
        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;
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
 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;
 }
示例#6
0
        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;
            }
        }
示例#7
0
 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;
 }
示例#9
0
 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();
 }
示例#10
0
 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;
 }
示例#11
0
文件: Car.cs 项目: YoniME/DN-EX3
 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();
 }
示例#12
0
 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)
 {
 }
示例#13
0
 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;
 }
示例#14
0
 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;
 }
示例#15
0
 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;
 }
示例#16
0
        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");
            }
        }
示例#17
0
        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);
        }
示例#18
0
        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"]);
            }
        }
示例#19
0
文件: Car.cs 项目: sigalbi/Garage
 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>");
     }
 }
示例#20
0
文件: Car.cs 项目: YoniME/DN-EX3
        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;
            }
        }
示例#21
0
 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;
 }
示例#22
0
        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);
        }
示例#23
0
文件: Car.cs 项目: yairm91/C-HW-Ex3
 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;
 }
示例#24
0
        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);
            }
        }
示例#25
0
        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;
        }
示例#26
0
        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;
        }
示例#27
0
        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)
 {
 }
示例#29
0
        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);
        }
示例#30
0
        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);
        }