Ejemplo n.º 1
0
        private void ChangeVehicleStatus()
        {
            System.Console.WriteLine("Please enter the ID of the vehicle you would like to change the status of:");
            string vehicleID             = System.Console.ReadLine();
            bool   VehicleExistsInGarage = m_Garage.DoesVehicleExistsInGarage(vehicleID);

            if (VehicleExistsInGarage)
            {
                GarageUIMenuMesseges.PrintAvailableVehicleStatusMenu();
                int selection = GetValidInput(1, 3);
                eStatusOfVehicleInGarage newVehicleStatus = (eStatusOfVehicleInGarage)selection;
                try
                {
                    m_Garage.ChangeVehicleStatus(vehicleID, newVehicleStatus);
                    GarageUIMenuMesseges.PrintOperationDone();
                }
                catch (Exception)
                {
                    System.Console.WriteLine("Error! Cannot change vehicle status because its already status: {0}!", newVehicleStatus);
                    GarageUIMenuMesseges.ClearAndPrintAnyKey();
                }
            }
            else
            {
                System.Console.WriteLine("Error! no vehicle with vehicle ID {0} in garage!{1}", vehicleID, Environment.NewLine);
                GarageUIMenuMesseges.ClearAndPrintAnyKey();
            }
        }
Ejemplo n.º 2
0
        private void ChargeVehicle()
        {
            System.Console.WriteLine("Please enter the ID of the vehicle you would like to charge:");
            string vehicleID             = System.Console.ReadLine();
            bool   VehicleExistsInGarage = m_Garage.DoesVehicleExistsInGarage(vehicleID);

            if (VehicleExistsInGarage)
            {
                if (m_Garage.GetVehicle(vehicleID).PowerType is PoweredByElectricity)
                {
                    float durationOfChargeTimeInMins = GetValidChargeTimeValue();
                    m_Garage.ChargeVehicle(vehicleID, durationOfChargeTimeInMins);
                    GarageUIMenuMesseges.PrintOperationDone();
                }
                else
                {
                    System.Console.WriteLine("Error! Can only charge vehicles that are powered by Electricity!");
                }
            }
            else
            {
                System.Console.WriteLine("Error! no vehicle with vehicle ID {0} in garage!{1}", vehicleID, Environment.NewLine);
                GarageUIMenuMesseges.ClearAndPrintAnyKey();
            }
        }
Ejemplo n.º 3
0
        private void AddVehicle()
        {
            string[] EnumVehicleNameStrings = Enum.GetNames(typeof(eVehicleType));

            for (int i = 0; i < EnumVehicleNameStrings.Length; i++)
            {
                EnumVehicleNameStrings[i] = FixEnumStringLayout(EnumVehicleNameStrings[i]);
            }

            try
            {
                GarageUIMenuMesseges.PrintVehicleTypeToAddMenu(EnumVehicleNameStrings);
                int          selection    = GetValidInput(1, 5);
                eVehicleType vehicleType  = (eVehicleType)selection;
                Vehicle      vehicleToAdd = VehicleFactory.ConstructVehicle(vehicleType);
                GetBaseValuesForVehicle(vehicleToAdd);
                List <string> inputReqMsgs  = vehicleToAdd.GetInputRequestMesseges();
                List <string> userInputList = new List <string>();

                foreach (string inputReqMsg in inputReqMsgs)
                {
                    System.Console.WriteLine(inputReqMsg);
                    string inputDataStr = System.Console.ReadLine();
                    userInputList.Add(inputDataStr);
                }

                vehicleToAdd.ExtractSpecificVehicleDataValues(userInputList);

                bool vehicleAlreadyInGarage = m_Garage.AddVehicleToGarage(vehicleToAdd.VehicleID, vehicleToAdd);

                if (vehicleAlreadyInGarage)
                {
                    System.Console.WriteLine("Error, vehicle already exists in garage!");
                    GarageUIMenuMesseges.ClearAndPrintAnyKey();
                }
                else
                {
                    GarageUIMenuMesseges.PrintOperationDone();
                }
            }
            catch (ValueOutOfRangeException ex)
            {
                System.Console.WriteLine(ex.ToString());
                GarageUIMenuMesseges.ClearAndPrintAnyKey();
            }
            catch (FormatException ex)
            {
                System.Console.WriteLine(ex.ToString());
                GarageUIMenuMesseges.ClearAndPrintAnyKey();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
                GarageUIMenuMesseges.ClearAndPrintAnyKey();
            }
        }
Ejemplo n.º 4
0
        private void FuelVehicle()
        {
            System.Console.WriteLine("Please enter the ID of the vehicle you would like to fuel:");
            string vehicleID             = System.Console.ReadLine();
            bool   VehicleExistsInGarage = m_Garage.DoesVehicleExistsInGarage(vehicleID);

            if (VehicleExistsInGarage)
            {
                Vehicle vehicleToFuel = m_Garage.GetVehicle(vehicleID);

                if (vehicleToFuel.PowerType is PoweredByFuel)
                {
                    GarageUIMenuMesseges.PrintFuelTypeMenu();
                    int       selection     = GetValidInput(1, 4);
                    eFuelType fuelTypeToAdd = (eFuelType)selection;

                    eFuelType vehicleFuelType = (vehicleToFuel.PowerType as PoweredByFuel).FuelType;

                    if (fuelTypeToAdd == vehicleFuelType)
                    {
                        try
                        {
                            float amountOfFuelToAdd = GetValidFuelToAddValue(fuelTypeToAdd);
                            m_Garage.FuelVehicle(vehicleID, fuelTypeToAdd, amountOfFuelToAdd);
                        }
                        catch (ValueOutOfRangeException ex)
                        {
                            System.Console.WriteLine(ex.ToString());
                        }

                        GarageUIMenuMesseges.PrintOperationDone();
                    }
                    else
                    {
                        System.Console.WriteLine("Error! cannot add fuel type {0} to a fuel type {1} vehicle!", Enum.GetName(typeof(eFuelType), fuelTypeToAdd), Enum.GetName(typeof(eFuelType), vehicleFuelType));
                        GarageUIMenuMesseges.ClearAndPrintAnyKey();
                    }
                }
                else
                {
                    System.Console.WriteLine("Error! Can only fuel vehicles that are powered by fuel!");
                    GarageUIMenuMesseges.ClearAndPrintAnyKey();
                }
            }
            else
            {
                System.Console.WriteLine("Error! no vehicle with vehicle ID {0} in garage!{1}", vehicleID, Environment.NewLine);
                GarageUIMenuMesseges.ClearAndPrintAnyKey();
            }
        }
Ejemplo n.º 5
0
        private void InflateVehicleWheelsToMaximum()
        {
            System.Console.WriteLine("Please enter the ID of the vehicle whos wheels you would like to inflate to maximum:");
            string vehicleID             = System.Console.ReadLine();
            bool   VehicleExistsInGarage = m_Garage.DoesVehicleExistsInGarage(vehicleID);

            if (VehicleExistsInGarage)
            {
                m_Garage.IncreaseAirPressureInWheelsToMaximum(vehicleID);
                GarageUIMenuMesseges.PrintOperationDone();
            }
            else
            {
                System.Console.WriteLine("No matching vehicles found in garage!{0}", Environment.NewLine);
            }
        }
Ejemplo n.º 6
0
        private void DisplayVehiclesIDList()
        {
            GarageUIMenuMesseges.PrintFilterOrNotMenu();
            int                      selection = GetValidInput(1, 2);
            List <string>            vehicleIDsList;
            eStatusOfVehicleInGarage vehicleStatusToFilterBy;
            string                   tempPrintStr;
            int                      i = 1;

            if (selection == k_Yes)
            {
                GarageUIMenuMesseges.PrintFilterByWhatVehicleStatusMenu();
                selection = GetValidInput(1, 3);

                vehicleStatusToFilterBy = (eStatusOfVehicleInGarage)selection;
                vehicleIDsList          = m_Garage.GetFilteredVehicleIDsList(vehicleStatusToFilterBy);

                string status = Enum.GetName(typeof(eStatusOfVehicleInGarage), vehicleStatusToFilterBy);
                tempPrintStr = string.Format(
                    @"Here are the ID numbers of the current vehicles inside the garage,
under the status of {0}: ",
                    status);
            }
            else
            {
                vehicleIDsList = m_Garage.GetVehicleIDsList();
                tempPrintStr   = "Here are the ID numbers of the current vehicles inside the garage:";
            }

            if (vehicleIDsList.Count > 0)
            {
                System.Console.WriteLine(tempPrintStr);
                foreach (string vehicleID in vehicleIDsList)
                {
                    System.Console.WriteLine(string.Format("{0}.{1}", i, vehicleID));
                    i++;
                }

                GarageUIMenuMesseges.PrintOperationDone();
            }
            else
            {
                System.Console.WriteLine("No matching vehicles found in garage!{0}", Environment.NewLine);
            }
        }
Ejemplo n.º 7
0
        public void MainMenu()
        {
            bool keepRunning = true;

            while (keepRunning)
            {
                GarageUIMenuMesseges.PrinteMainMenu();
                eMainMenu selection = (eMainMenu)GetValidInput(1, 8);
                switch (selection)
                {
                case eMainMenu.AddVehicle:
                    AddVehicle();
                    break;

                case eMainMenu.DisplayVehiclesIDList:
                    DisplayVehiclesIDList();
                    break;

                case eMainMenu.ChangeVehicleStatus:
                    ChangeVehicleStatus();
                    break;

                case eMainMenu.InflateVehicleWheelsToMaximum:
                    InflateVehicleWheelsToMaximum();
                    break;

                case eMainMenu.FuelVehicle:
                    FuelVehicle();
                    break;

                case eMainMenu.ChargeVehicle:
                    ChargeVehicle();
                    break;

                case eMainMenu.PrintVehicleInformation:
                    PrintVehicleInformation();
                    break;

                case eMainMenu.Exit:
                    GarageUIMenuMesseges.PrintExitMessege();
                    keepRunning = false;
                    break;
                }
            }
        }
Ejemplo n.º 8
0
        private void PrintVehicleInformation()
        {
            System.Console.WriteLine("Please enter the ID of the vehicle you would like to get information about:");
            string vehicleID             = System.Console.ReadLine();
            bool   VehicleExistsInGarage = m_Garage.DoesVehicleExistsInGarage(vehicleID);

            if (VehicleExistsInGarage)
            {
                Vehicle       vehicle = m_Garage.GetVehicle(vehicleID);
                StringBuilder infoStr = new StringBuilder();

                infoStr.Append("Vehicle ID: ");
                infoStr.Append(vehicleID);
                infoStr.Append(Environment.NewLine);
                infoStr.Append(Environment.NewLine);

                infoStr.Append("Model Name: ");
                infoStr.Append(vehicle.ModelName);
                infoStr.Append(Environment.NewLine);
                infoStr.Append(Environment.NewLine);

                infoStr.Append("Owner Name: ");
                infoStr.Append(vehicle.OwnerCard.VehicleOwnerName);
                infoStr.Append(Environment.NewLine);
                infoStr.Append(Environment.NewLine);

                string vehicleStatusNameStr = Enum.GetName(typeof(eStatusOfVehicleInGarage), vehicle.OwnerCard.VehicleStatus);

                infoStr.Append("Vehicle Status: ");
                infoStr.Append(vehicleStatusNameStr);
                infoStr.Append(Environment.NewLine);
                infoStr.Append(Environment.NewLine);

                infoStr.Append("Percent of remaining energy in power source: ");
                infoStr.Append(vehicle.GetPercentOfRemainingEnergyInPowerSource());
                infoStr.Append(Environment.NewLine);
                infoStr.Append(Environment.NewLine);

                infoStr.Append("Current air pressure in vehicle wheels: ");
                infoStr.Append(vehicle.VehicleWheels[0].CurrentAirPressure);
                infoStr.Append(Environment.NewLine);
                infoStr.Append(Environment.NewLine);

                infoStr.Append("Wheels manufacturer: ");
                infoStr.Append(vehicle.VehicleWheels[0].ManufacturerName);
                infoStr.Append(Environment.NewLine);
                infoStr.Append(Environment.NewLine);

                if (vehicle.PowerType is PoweredByFuel)
                {
                    infoStr.Append("Fuel type: ");
                    string fuelTypeStr = Enum.GetName(typeof(eFuelType), (vehicle.PowerType as PoweredByFuel).FuelType);
                    infoStr.Append(fuelTypeStr);
                    infoStr.Append(Environment.NewLine);
                    infoStr.Append(Environment.NewLine);

                    infoStr.Append("Current amount of fuel: ");
                    infoStr.Append((vehicle.PowerType as PoweredByFuel).CurrentAmountOfFuel);
                    infoStr.Append(Environment.NewLine);
                    infoStr.Append(Environment.NewLine);
                }
                else
                {
                    infoStr.Append("Remaining battery time in hours: ");
                    string batteryTimeStr = (vehicle.PowerType as PoweredByElectricity).RemainingBatteryTimeInHours.ToString();
                    infoStr.Append(batteryTimeStr);
                    infoStr.Append(Environment.NewLine);
                    infoStr.Append(Environment.NewLine);
                }

                StringBuilder finalInfoStr = vehicle.GetSpecificVehicleInformation(infoStr);

                System.Console.WriteLine(finalInfoStr.ToString());

                GarageUIMenuMesseges.PrintOperationDone();
            }
            else
            {
                System.Console.WriteLine("Vehicle ID doesnt exist in garage!");
            }
        }