Esempio n. 1
0
        private FueledEngine.eFuelType getFuelTypeInput()
        {
            int  optionAsInt        = 0;
            bool isInputValid       = false;
            int  howManyMenuOptions = Enum.GetNames(typeof(FueledEngine.eFuelType)).Length;

            while (isInputValid == false)
            {
                string optionSelectedAsString = Console.ReadLine();
                isInputValid = checkMenuOptionSelectedThenPrintCheckAndReturnAsInteger(
                    optionSelectedAsString,
                    howManyMenuOptions,
                    out optionAsInt);
            }

            FueledEngine.eFuelType optionSelected = 0;
            foreach (FueledEngine.eFuelType menuOption in Enum.GetValues(typeof(FueledEngine.eFuelType)))
            {
                if ((int)menuOption == optionAsInt)
                {
                    optionSelected = menuOption;
                }
            }

            return(optionSelected);
        }
        public static FueledEngine.eFuelType ParseFuelTypeInput(string i_Input)
        {
            FueledEngine.eFuelType userOption = 0;
            switch ((FueledEngine.eFuelType)Enum.Parse(typeof(FueledEngine.eFuelType), i_Input))
            {
            case FueledEngine.eFuelType.Octan95:
                userOption = FueledEngine.eFuelType.Octan95;
                break;

            case FueledEngine.eFuelType.Octan96:
                userOption = FueledEngine.eFuelType.Octan96;
                break;

            case FueledEngine.eFuelType.Octan98:
                userOption = FueledEngine.eFuelType.Octan98;
                break;

            case FueledEngine.eFuelType.Soler:
                userOption = FueledEngine.eFuelType.Soler;
                break;

            default:
                throw new FormatException("Invalid input, must be 'Octan95', 'Octan96', Octan98' or 'Soler'");
            }

            return(userOption);
        }
Esempio n. 3
0
        public void RePowerVehcile(bool isFuelEngine)
        {
            bool   isValidInput       = false;
            float  repowerAmountInput = 0;
            string fuelTypeInput      = string.Empty;

            OutputToConsole("Enter license plate number:");
            m_CurrentVehicleLicensePlate = InputFromConsole();
            if (isFuelEngine)
            {
                OutputToConsole("Enter the amount you wish to fuel:");
            }
            else
            {
                OutputToConsole("Enter how much time you wish to charge:");
            }

            while (!isValidInput)
            {
                try
                {
                    repowerAmountInput = UserInputExceptions.ParseFloatInput(InputFromConsole());
                    isValidInput       = true;
                }
                catch (FormatException e)
                {
                    OutputToConsole(e.Message);
                    continue;
                }
            }

            ///now try to parse the input regarding rePower the vehicle
            try
            {
                ///repower the vehicle
                if (isFuelEngine)
                {
                    OutputToConsole(string.Format(
                                        @"Enter Fuel type:
Enter 'Octan95' (or 1), 'Ocatan96' (or 2), , 'Ocatan98' (or 3) or 'Soler' (or 4)"));
                    fuelTypeInput = InputFromConsole();
                    FueledEngine.eFuelType parsedFuelType = UserInputExceptions.ParseFuelTypeInput(fuelTypeInput);
                    UserInputExceptions.CheckIfRepowerArgsExceptions(m_CurrentVehicleLicensePlate, repowerAmountInput, isFuelEngine, m_GarageManager, m_MainClientLicensePlate, parsedFuelType);
                    this.m_GarageManager.FuelVehicle(m_MainClientLicensePlate, m_CurrentVehicleLicensePlate, parsedFuelType, repowerAmountInput);
                    OutputToConsole(string.Format("vehicle {0} has been fueled with {1} liters", m_CurrentVehicleLicensePlate, repowerAmountInput));
                }
                else
                {
                    UserInputExceptions.CheckIfRepowerArgsExceptions(m_CurrentVehicleLicensePlate, repowerAmountInput, isFuelEngine, m_GarageManager, m_MainClientLicensePlate);
                    this.m_GarageManager.ChargeVehicle(m_MainClientLicensePlate, m_CurrentVehicleLicensePlate, repowerAmountInput);
                    OutputToConsole(string.Format("vehicle {0} has been charged with {1} hours", m_CurrentVehicleLicensePlate, repowerAmountInput));
                }
            }
            catch (Exception e)
            {
                OutputToConsole(e.Message);
            }
        }
Esempio n. 4
0
        private void refuelVehicle()
        {
            string licenseNumber = getLicenseNumberInput();

            FueledEngine.eFuelType fuelType = getFuelTypeInput();
            float amountOfFuel = getFuelAmountInput();

            r_Garage.RefuelClientVehicleByLicenseNumber(licenseNumber, fuelType, amountOfFuel);
        }
Esempio n. 5
0
        public void FuelVehcile(string i_LicensePlate, FueledEngine.eFuelType I_FuelType, float i_FuelAmount)
        {
            GarageClient client = null;

            if (m_GarageDictonary.TryGetValue(i_LicensePlate, out client))
            {
                ////need execption for fuel type here! (other exceptions are taking care of
                client.m_Vehicle.GetEngine().RePower(i_FuelAmount);
            }
        }
Esempio n. 6
0
        private static Truck getTruck(ArgumentConsumersContainer i_VehicleArgumentConsumersContainer)
        {
            Dictionary <string, ArgumentConsumer> truckArguments = i_VehicleArgumentConsumersContainer.GetConsumers;
            float remainingFuel = float.Parse(truckArguments[Keys.RemainingFuel].ValueFromUser);

            FueledEngine.eFuelType fuelType = FueledEngine.eFuelType.Soler;
            Engine engine = new FueledEngine(remainingFuel, EngineCapacityConstant.FueledTruckEngineCapacity, fuelType);
            Truck  truck  = getTruck(truckArguments, engine);

            return(truck);
        }
Esempio n. 7
0
        private static Motorcycle getMotorcycle(ArgumentConsumersContainer i_VehicleArgumentConsumersContainer)
        {
            Dictionary <string, ArgumentConsumer> motorcycleArguments = i_VehicleArgumentConsumersContainer.GetConsumers;
            float remainingFuel = float.Parse(motorcycleArguments[Keys.RemainingFuel].ValueFromUser);

            FueledEngine.eFuelType fuelType = FueledEngine.eFuelType.Octan95;
            Engine     engine     = new FueledEngine(remainingFuel, EngineCapacityConstant.ElectricMotorcycleEngineCapacity, fuelType);
            Motorcycle motorcycle = getMotorcycle(motorcycleArguments, engine);

            return(motorcycle);
        }
Esempio n. 8
0
        private static Car getFueledCar(ArgumentConsumersContainer i_VehicleArgumentConsumersContainer)
        {
            Dictionary <string, ArgumentConsumer> carArguments = i_VehicleArgumentConsumersContainer.GetConsumers;
            float remainingFuel = float.Parse(carArguments[Keys.RemainingFuel].ValueFromUser);

            FueledEngine.eFuelType fuelType = FueledEngine.eFuelType.Octan96;
            Engine engine = new FueledEngine(remainingFuel, EngineCapacityConstant.FueledCarEngineCapacity, fuelType);
            Car    car    = getCar(carArguments, engine);

            return(car);
        }
Esempio n. 9
0
        public void RefuelVehicle(float i_AmountOfFuel, FueledEngine.eFuelType i_WantedFuelType)
        {
            FueledEngine clientVehicleEngine = r_VehicleOfClient.VehicleEngine as FueledEngine;

            if (clientVehicleEngine == null)
            {
                throw new ArgumentException("Client vehicle engine can't be filled with fuel");
            }

            clientVehicleEngine.AddFuel(i_AmountOfFuel, i_WantedFuelType);
        }
Esempio n. 10
0
 public FueledcBike(
     string i_ModelType,
     string i_LicensePlate,
     string i_WheelManufacturer,
     float[] i_TirePressures,
     FueledEngine.eFuelType i_FuelType,
     float i_CurrentFuelAmount,
     eLicenseType i_LicenseType,
     int i_EngineVolume)
 {
     this.m_ModelType    = i_ModelType;
     this.m_LicensePlate = i_LicensePlate;
     this.m_Wheels.Add(new Wheel(i_WheelManufacturer, i_TirePressures[0], k_MaxTirePressure));
     this.m_Wheels.Add(new Wheel(i_WheelManufacturer, i_TirePressures[1], k_MaxTirePressure));
     this.m_Engine = new FueledEngine(i_CurrentFuelAmount, k_MaxFueledEngine, FueledEngine.eFuelType.Octan95);
     this.m_EnergyPrecentageLeft = i_CurrentFuelAmount / k_MaxFueledEngine;
     this.m_LicenseType          = i_LicenseType;
     this.m_EngineVolume         = i_EngineVolume;
 }
Esempio n. 11
0
        public Truck(
            string i_ModelType,
            string i_LicensePlate,
            string i_WheelManufacturer,
            float[] i_TirePressures,
            FueledEngine.eFuelType i_FuelType,
            float i_CurrentFuelAmount)
        {
            this.m_ModelType    = i_ModelType;
            this.m_LicensePlate = i_LicensePlate;

            foreach (float currentTirePressure in i_TirePressures)
            {
                this.m_Wheels.Add(new Wheel(i_WheelManufacturer, currentTirePressure, k_MaxTirePressure));
            }

            this.m_Engine = new FueledEngine(i_CurrentFuelAmount, k_MaxFuelCapacity, k_FuelType);
            this.m_EnergyPrecentageLeft = i_CurrentFuelAmount / k_MaxFuelCapacity;
        }
Esempio n. 12
0
        public FueledCar(
            string i_ModelType,
            string i_LicensePlate,
            string i_WheelManufacturer,
            float[] i_TirePressures,
            FueledEngine.eFuelType i_FuelType,
            float i_CurrentFuelAmount,
            eCarColor i_CarColor,
            eNumOfDoors i_NumOfDoors)
        {
            this.m_ModelType    = i_ModelType;
            this.m_LicensePlate = i_LicensePlate;
            foreach (float currentTirePressure in i_TirePressures)
            {
                this.m_Wheels.Add(new Wheel(i_WheelManufacturer, currentTirePressure, k_MaxTirePressure));
            }

            this.m_Engine = new FueledEngine(i_CurrentFuelAmount, k_MaxFueledEngine, FueledEngine.eFuelType.Octan98);
            this.m_EnergyPrecentageLeft = i_CurrentFuelAmount / k_MaxFueledEngine;
            this.m_CarColor             = i_CarColor;
            this.m_NumOfDoors           = i_NumOfDoors;
        }
        public static void CheckIfRepowerArgsExceptions(string i_LicensePlate, float i_RepowerAmount, bool i_IsFuelEngine, GarageManager i_GarageManager, string i_MainClientLicensePlate, FueledEngine.eFuelType i_FuelType = FueledEngine.eFuelType.None)
        {
            GarageClient o_Client = null;

            GarageClient.SingleVehicleInfo o_InnerDict = null;
            if (i_GarageManager.m_GarageDictonary.TryGetValue(i_MainClientLicensePlate, out o_Client))
            {
                if (!o_Client.m_Vehicles.TryGetValue(i_LicensePlate, out o_InnerDict))
                {
                    throw new Exception("license plate was not found in the garage");
                }
            }

            if (o_InnerDict.m_Vehicle.m_Engine.GetEngineType() == Engine.eEngineType.Electric && i_IsFuelEngine)
            {
                throw new Exception("vehicle cannot be charged because it is not a fueled vehicle");
            }

            if (o_InnerDict.m_Vehicle.m_Engine.GetEngineType() == Engine.eEngineType.Fuel && !i_IsFuelEngine)
            {
                throw new Exception("vehicle cannot be charged because it is not an electric vehicle");
            }

            if (i_RepowerAmount > o_InnerDict.m_Vehicle.m_Engine.getMaxPowerAmount())
            {
                if (i_IsFuelEngine)
                {
                    throw new Exception("Fuel amount requested is greater than the fuel tank capacity");
                }
                else
                {
                    throw new Exception("charge time requested is greater than the max charge time possible");
                }
            }

            if (o_InnerDict.m_Vehicle.m_Engine is FueledEngine)
            {
                FueledEngine currentFueledEngine = (FueledEngine)o_InnerDict.m_Vehicle.m_Engine;
                if (currentFueledEngine.GetFuelType() != i_FuelType)
                {
                    throw new Exception(string.Format("Fuel type requested, does not match the fuel type of this vehicle ({0}).", currentFueledEngine.GetFuelType()));
                }
            }
        }
Esempio n. 14
0
        public void FuelVehicle(string i_MainLicensePlate, string i_CurrentLicensePlate, FueledEngine.eFuelType i_FuelType, float i_FuelAmount)
        {
            GarageClient o_Client = null;

            GarageClient.SingleVehicleInfo o_InnerDict = null;
            if (m_GarageDictonary.TryGetValue(i_MainLicensePlate, out o_Client))
            {
                if (o_Client.m_Vehicles.TryGetValue(i_CurrentLicensePlate, out o_InnerDict))
                {
                    o_InnerDict.m_Vehicle.GetEngine().RePower(i_FuelAmount);
                }
            }
        }
Esempio n. 15
0
        public void RefuelClientVehicleByLicenseNumber(string i_LicenseNumber, FueledEngine.eFuelType i_WantedFuelType, float i_AmountOfFuel)
        {
            ClientVehicle clientVehiclesToRefuel = findClientVehicleInGarageByLicenseNumber(i_LicenseNumber);

            clientVehiclesToRefuel.RefuelVehicle(i_AmountOfFuel, i_WantedFuelType);
        }