Esempio n. 1
0
 private static void tryEnterVehicleToTheGarage(Garage i_Garage, string i_LicensePlate)
 {
     if (i_Garage.IsVehicleInGarage(i_LicensePlate))
     {
         Console.WriteLine("Your Vehicle Already In The Garage.");
         i_Garage.ChangeVehicleStatus(i_LicensePlate, Garage.eVehicleStatus.InProgress);
     }
     else
     {
         string ownerName, ownerPhone;
         getOwnerDetails(out ownerName, out ownerPhone);
         i_Garage.EnterNewVehicle(ownerName, ownerPhone, getVehicleFromClient(i_LicensePlate, i_Garage));
     }
 }
Esempio n. 2
0
        private void changeVehicleStatusMenu()
        {
            try
            {
                string userChoice;
                string registrationNumber = getExistingRegistrationNumberFromUser();

                {
                    userChoice = InputManager.GetUserChoice(
                        @"Choose new status:
1. In repair.
2. Fixed.
3. Paid.
Please Enter one of the above:
>> ",
                        1,
                        2,
                        3);
                }

                Console.Clear();
                m_Garage.ChangeVehicleStatus(registrationNumber, int.Parse(userChoice));
                Console.WriteLine("Changing vehicle status was operated successfully.");
            }
            catch (ArgumentException i_ArgumentException)
            {
                if (i_ArgumentException.Message == "Vehicle_Not_Exist")
                {
                    Console.WriteLine("There is no vehicle in the garage with the entered registaration number.");
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Error: Input format does not match the format type required.{0}", Environment.NewLine);
            }
            catch (Exception i_Ex)
            {
                if (i_Ex.Message == "Invalid data input")
                {
                    Console.WriteLine("Error: {0}.{1}", i_Ex.Message, Environment.NewLine);
                }
                else
                {
                    Console.WriteLine("Error: Unknown.{0}", Environment.NewLine);
                }
            }
        }
Esempio n. 3
0
 public void changeCarStatus()
 {
     m_UserDisplay.ClearAndDisplayMessage("You have chosen to change the status of a vehicle who is in the garage");
     try
     {
         m_Garage.ChangeVehicleStatus(m_ChangeStatus.GetLicenseNumberForChangingStatus(), m_ChangeStatus.GetGarageStatus());
         m_UserDisplay.ClearAndDisplayMessage("Vehicle status changed!");
     }
     catch (Exception exception)
     {
         m_UserDisplay.displayExceptionMessage(exception);
     }
     finally
     {
         m_UserDisplay.PressAnyKeyToContinue();
     }
 }
        /*** Options 3 - 7 ***/
        private void menuOptions(int i_MainMenuSelection)
        {
            int userChoice;

            System.Console.Clear();
            string  licenseNumber;
            Vehicle currentVehicle = this.promptUserForLicenseNumber(out licenseNumber);

            if (currentVehicle != null)
            {
                switch (i_MainMenuSelection)
                {
                case 3:
                    /* 3) Change a vehicle status */
                    System.Console.WriteLine(createMenuStringFromEnum(typeof(Vehicle.eVehicleStatus), "Enter a Vehicle Status"));
                    userChoice = promptUserForMenuSelection(Enum.GetNames(typeof(Vehicle.eVehicleStatus)).Length);
                    try
                    {
                        m_Garage.ChangeVehicleStatus(licenseNumber, (Vehicle.eVehicleStatus)(userChoice - 1));
                        string vehicleStatusMessage = string.Format(@"The status of this vehicle is now: {0}
", (Vehicle.eVehicleStatus)(userChoice - 1));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                    break;

                case 4:
                    /* 4) Inflate tires to max */
                    currentVehicle.InflateAllWheelsToMax();
                    System.Console.Clear();
                    System.Console.WriteLine("Inflation of tires succesful.");
                    //System.Console.WriteLine(Environment.NewLine);
                    break;

                case 5:
                    /* 5) Refuel vehicle */

                    FuelBasedEngine fuelEngine = currentVehicle.Engine as FuelBasedEngine;

                    if (fuelEngine == null)
                    {
                        try
                        {
                            throw new FormatException();
                        }
                        catch (FormatException)
                        {
                            Console.WriteLine("This vehicle does not have a fuel based engine. Refuel Failed");
                            System.Console.WriteLine(Environment.NewLine);
                        }
                    }
                    else
                    {
                        System.Console.WriteLine(createMenuStringFromEnum(typeof(FuelBasedEngine.eFuelType), "Enter a Fuel Type"));
                        userChoice = this.promptUserForMenuSelection(Enum.GetNames(typeof(FuelBasedEngine.eFuelType)).Length);
                        string refuelMessage = string.Format(@"Current Amount Of Fuel: {0}
Maximum Amount Of Fuel: {1}
Please enter amount to refuel:", fuelEngine.CurrentAmountOfFuel, fuelEngine.MaxAmountOfFuel);
                        System.Console.WriteLine(refuelMessage);
                        float amountToRefuel = this.getFloatFromUser(0, fuelEngine.MaxAmountOfFuel - fuelEngine.CurrentAmountOfFuel);

                        try
                        {
                            this.m_Garage.RefuelVehicle(licenseNumber, (FuelBasedEngine.eFuelType)(userChoice - 1), amountToRefuel);
                            System.Console.WriteLine("Refuel Succesful.");
                        }
                        catch (ArgumentException)
                        {
                            string fuelTypeExceptionMessage = string.Format("Wrong fuel type for this vehicle, expected {0}. Refuel Failed.", fuelEngine.FuelType);
                            Console.WriteLine(fuelTypeExceptionMessage);
                        }
                        System.Console.WriteLine(Environment.NewLine);
                    }
                    break;

                case 6:
                    /* 6) charge vehicle */
                    ElectricBasedEngine electricEngine = currentVehicle.Engine as ElectricBasedEngine;

                    if (electricEngine == null)
                    {
                        try
                        {
                            throw new FormatException();
                        }
                        catch (FormatException)
                        {
                            System.Console.WriteLine("This vehicle does not have an electric based engine. Recharge Failed.");
                        }
                    }
                    string rechargeMessage = string.Format(@"Remaining time of engine operation in hours: {0}
Max time of engine operations in hours: {1}
Please enter number of minutes to recharge:", electricEngine.RemainingTimeOnBattery, electricEngine.MaxBatteryLife);
                    System.Console.WriteLine(rechargeMessage);
                    float amountToRecharge = this.getFloatFromUser(0, (electricEngine.MaxBatteryLife - electricEngine.RemainingTimeOnBattery) * 60);
                    m_Garage.ChargeElectricVehice(licenseNumber, amountToRecharge);
                    System.Console.WriteLine("Recharge Succesful.");
                    System.Console.WriteLine(Environment.NewLine);
                    break;

                case 7:
                    /* 7) Display vehicle information */
                    System.Console.Clear();
                    System.Console.WriteLine(currentVehicle.ToString());
                    System.Console.WriteLine(Environment.NewLine);
                    break;
                }
            }
            else
            {
                System.Console.WriteLine(string.Format("Vehicle with licence number {0} is not in the garage.{1}", licenseNumber, Environment.NewLine));
            }

            returnToMenuOrQuit();
        }
Esempio n. 5
0
        public static void Run()
        {
            Garage myGarage = new Garage();

            Console.WriteLine(string.Format("Welcome To The Garage!"));
            Garage.eGarageOptions?clientChoosement = null;
            string     licensePlate  = null;
            const bool k_GarageExist = true;

            do
            {
                Console.WriteLine();
                printActionOptionsToClient();
                clientChoosement = getClientChoosement();
                if (clientChoosement != Garage.eGarageOptions.ShowLicensePlates)
                {
                    licensePlate = GetLicensePlate();
                    if (clientChoosement != Garage.eGarageOptions.EnterVehicle)
                    {
                        if (myGarage.IsVehicleInGarage(licensePlate) == false)
                        {
                            Console.WriteLine("This Vehicle Is Not In The Garage.");
                            continue;
                        }
                    }
                }

                switch (clientChoosement)
                {
                case Garage.eGarageOptions.EnterVehicle:
                {
                    tryEnterVehicleToTheGarage(myGarage, licensePlate);
                    break;
                }

                case Garage.eGarageOptions.ShowLicensePlates:
                {
                    showLicensePlates(myGarage);
                    break;
                }

                case Garage.eGarageOptions.ChangeVehicleStatus:
                {
                    Garage.eVehicleStatus vehicleStatus = getVehicleStatus();
                    myGarage.ChangeVehicleStatus(licensePlate, vehicleStatus);
                    break;
                }

                case Garage.eGarageOptions.InflateTires:
                {
                    myGarage.InflateTires(licensePlate);
                    break;
                }

                case Garage.eGarageOptions.FuelTank:
                {
                    tryFuelTank(myGarage, licensePlate);
                    break;
                }

                case Garage.eGarageOptions.ChargeElectricVehicle:
                {
                    tryChargeElectricVehicle(myGarage, licensePlate);
                    break;
                }

                case Garage.eGarageOptions.ShowVehicleDetails:
                {
                    Console.WriteLine(myGarage.GetVehicleDetailsString(licensePlate));
                    break;
                }

                default:
                {
                    break;
                }
                }
            }while (k_GarageExist);
        }