Example #1
0
        /// <summary>
        /// asks the user for a license number and and the amount of fuel he wants to add
        /// </summary>
        private void chargeVehicle()
        {
            string licenseNum = getExistingLicenseNumberFromUser();

            if (!m_Garage.IsElectricVehicle(licenseNum))
            {
                Console.WriteLine("Can't charge an fuel vehicle");
            }
            else
            {
                while (true)
                {
                    try
                    {
                        float amountToAdd = getValidFloatFromUser("How much minutes of charge to add?");
                        m_Garage.ChargeVehicle(licenseNum, amountToAdd);
                        break;
                    }
                    catch (GarageLogic.ValueOutOfRangeException e)
                    {
                        Console.WriteLine(e.Message);
                        System.Threading.Thread.Sleep(1500);
                        continue;
                    }
                }

                Console.WriteLine("Your action has been done");
            }
        }
Example #2
0
        private void goToChoice(int i_Choice)
        {
            Console.Clear();
            switch (i_Choice)
            {
            case ((int)eMenuOptions.InsertNewCar):
                m_GarageManager.InsertNewCar();
                break;

            case ((int)eMenuOptions.ShowAllDrivingLicenses):
                m_GarageManager.ShowAllLicenseNumbers();
                break;

            case ((int)eMenuOptions.ChangeVehicleStatus):
                m_GarageManager.ChangeVehicleStatus();
                break;

            case ((int)eMenuOptions.AddPressureToMax):
                m_GarageManager.FillPressureToMax();
                break;

            case ((int)eMenuOptions.AddFuel):
                m_GarageManager.AddFuel();
                break;

            case ((int)eMenuOptions.Charge):
                m_GarageManager.ChargeVehicle();
                break;

            case ((int)eMenuOptions.ShowFullVehicleDetails):
                m_GarageManager.ShowFullVehicleDetails();
                break;
            }
        }
Example #3
0
        private void chargeElectricVehicle()
        {
            Console.WriteLine("Hello, please enter vehicle's License number in order to charge:");
            string vehicleLicense = getNotEmptyInput();
            bool   carIsInGarage  = true;

            try
            {
                m_LogicManager.IsInGarage(vehicleLicense);
                carIsInGarage = true;
            }
            catch (FormatException)
            {
                Console.WriteLine("This vehicle License number not exsit in our garage, press enter for main menu");
                Console.ReadLine();
                carIsInGarage = false;;
            }

            while (true & carIsInGarage)
            {
                Console.WriteLine("How many minutes would you like to charge your vehicle?");
                float numberOfMinutes = getFloatInput();
                try
                {
                    m_LogicManager.ChargeVehicle(vehicleLicense, numberOfMinutes);
                    Console.WriteLine("It was done now {0} charged with the amount you asked: {1}", vehicleLicense, numberOfMinutes);
                    Console.ReadLine();
                    break;
                }
                catch (FormatException)
                {
                    Console.WriteLine("You trying to charge a fuel engiane, please go to refuel option at the main menu (option number 5)");
                    Console.ReadLine();
                    break;
                }
                catch (ValueOutOfRangeException ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(@"want to try again?
(1) Yes
(2) No");
                    string userInput = getNumberInRange(1, 2, true);
                    if (userInput.Equals("2"))
                    {
                        break;
                    }
                }
            }
        }
Example #4
0
        private void chargeVehicleUi(string i_LicenseNumber)
        {
            bool isValidInput = false;

            do
            {
                try
                {
                    while (!r_CurrentGarage.AllVehicles.ContainsKey(i_LicenseNumber))
                    {
                        Console.WriteLine(@"This vehicle is not in the garage, please enter a valid License Number
Please chose a vehicle from the list:");
                        printVehiclesByEngineType(typeof(ElectricEngine).ToString());
                        i_LicenseNumber = getLicenseNumber();
                    }

                    Console.WriteLine("Please enter how many hour you want to charge battery");
                    string hoursToFillString = Console.ReadLine();
                    float  hoursToFill;

                    while (!float.TryParse(hoursToFillString, out hoursToFill))
                    {
                        Console.WriteLine("Please enter a number");
                        hoursToFillString = Console.ReadLine();
                    }

                    r_CurrentGarage.ChargeVehicle(i_LicenseNumber, hoursToFill);
                    isValidInput = true;
                }
                catch (KeyNotFoundException keyNotFound)
                {
                    Console.WriteLine(keyNotFound.Message);
                    isValidInput = true;
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }while(!isValidInput);
        }
Example #5
0
        private void charageVehicleOp()
        {
            string requestedLicenseNumber;
            float  timeToCharge;

            getValidLicenseNumber(out requestedLicenseNumber);
            timeToCharge = getEnergyAmountToFill();
            Console.Clear();
            try
            {
                m_GarageManager.ChargeVehicle(requestedLicenseNumber, timeToCharge);
                Console.WriteLine("Successfuly charged vehicle with license number:{0}", requestedLicenseNumber);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(string.Format("Error has occured!{0}{1}", Environment.NewLine, e.Message));
            }
            catch (ValueOutOfRangeException e)
            {
                Console.WriteLine(string.Format("Error has occured!{0}{1}", Environment.NewLine, e.Message));
            }
        }
Example #6
0
        private void addEnergy(string i_LicenseNumber, eEnergySource i_EnergySource)
        {
            NumericalInputScreen numericalInputScreen = r_Screens[eUIScreens.NumericalInput] as NumericalInputScreen;
            eFuel?fuel = null;

            if (i_EnergySource == eEnergySource.Electricity)
            {
                numericalInputScreen.SetMassageToDisplay("Enter Time To Add");
            }
            else
            {
                MenuScreen fuelScreen = r_Screens[eUIScreens.FuelType] as MenuScreen;
                fuelScreen.Display(out string fuelTypeStr);
                fuel = (eFuel)parseMenuOption(fuelTypeStr);
                numericalInputScreen.SetMassageToDisplay("Enter Amount of Fuel To Add");
            }

            numericalInputScreen.Display(out string energyToAddStr);
            float energyToAdd = float.Parse(energyToAddStr);

            try
            {
                if (i_EnergySource == eEnergySource.Electricity)
                {
                    r_GarageManager.ChargeVehicle(i_LicenseNumber, energyToAdd);
                }
                else
                {
                    r_GarageManager.FuelVehicle(i_LicenseNumber, fuel.Value, energyToAdd);
                }
            }
            catch (Exception exception)
            {
                ScreenUtils.Display(exception.ToString());
                ScreenUtils.Freeze();
            }
        }