Esempio n. 1
0
        // charge energy for an existing suitable type vehicle
        internal void ChargeElectricVehicle(GarageLogic.Garage i_Garage)
        {
            // gets license number and checks if exist in garage, if not may exit to main menu
            m_CurrentLicnese = GetLicense(i_Garage);
            if (m_CurrentLicnese.Equals("-1"))
            {
                return;
            }

            // sets and validate amount of minutes to charge vehicle
            Console.WriteLine("Please enter amount of minutes to charge");
            string minutes         = Console.ReadLine();
            float  minutesToCharge = 0;
            bool   isMinutes       = float.TryParse(minutes, out minutesToCharge);

            while (!isMinutes)
            {
                Console.WriteLine("Please enter minutes as float number");
                minutes   = Console.ReadLine();
                isMinutes = float.TryParse(minutes, out minutesToCharge);
            }

            // try to charge vehicle, if vehicle is not suitable, brings back to main menu
            try
            {
                i_Garage.ChargeEnergy(m_CurrentLicnese, minutesToCharge);
            }
            catch (Exception)
            {
                Console.WriteLine("This vehicle is not electrical, plase choose a different option in Main Menu");
                Console.WriteLine("Press any key to return to Main Menu");
                Console.ReadLine();
                return;
            }

            // show success message and takes back to main menu
            SuccessFinishOperation();
        }