/**
         * This methods gets the vehicle type from the user
         */
        private VehicleBuilder.eVehicleType getVehicleType()
        {
            ConsoleUtils.ClearConsoleAndWrite("Pick a vehicle type:");
            ConsoleUtils.PrintEnum(typeof(VehicleBuilder.eVehicleType));
            string userInput = Console.ReadLine();

            return((VehicleBuilder.eVehicleType)ConsoleUtils.CheckEnumValue(typeof(VehicleBuilder.eVehicleType), userInput));
        }
        /**
         * This method gets license number from the user
         */
        private string getLicenseNumber()
        {
            ConsoleUtils.ClearConsoleAndWrite("Enter the license number of the vehicle");
            string userInput = Console.ReadLine();

            userInput = ConsoleUtils.CheckStringInput(userInput, "License number");

            return(userInput);
        }
Beispiel #3
0
        /**
         * This method validates the amount of fuel.
         */
        private void checkForValidAmountOfFuel(string i_UserInput)
        {
            string userInput = i_UserInput;

            while (!float.TryParse(userInput, out this.m_AmountForFuel) || m_AmountForFuel < 0)
            {
                ConsoleUtils.ClearConsoleAndWrite("Amount of fuel is invalid, please enter a valid amount");
                userInput = Console.ReadLine();
            }
        }
        /**
         * This method asks for the license number of the vehicle.
         */
        private void getDetailsForStatusChange()
        {
            ConsoleUtils.ClearConsoleAndWrite("Please enter the License number of the vehicle you would like to change the status:");
            this.m_LicenseNumber = ConsoleUtils.CheckForValidLicenseNumber(Console.ReadLine());
            ConsoleUtils.ClearConsoleAndWrite("Please enter the number of the status you would like");
            Console.WriteLine(@"1.In repair
2.Repaired
3.Payed for");
            m_NewVehicleStatus = checkForValidVehicleStatus(Console.ReadLine());
        }
        /**
         * This method gets the model name of the vehicle
         */
        private string getVehicleModel()
        {
            string model = "";

            ConsoleUtils.ClearConsoleAndWrite("Enter the model of the vehicle");
            model = Console.ReadLine();
            model = ConsoleUtils.CheckStringInput(model, "Model type");

            return(model);
        }
 /**
  * This method asks for details for recharge.
  */
 private void getDetailsForRecharge()
 {
     ConsoleUtils.ClearConsoleAndWrite("Please enter the license number of the vehicle you would like to charge:");
     this.m_LicenseNumber = ConsoleUtils.CheckForValidLicenseNumber(Console.ReadLine());
     if (m_CheckForEnergyType = checkForValidEnergyType(m_LicenseNumber))
     {
         ConsoleUtils.ClearConsoleAndWrite("Please enter the amount of time to charge the battery (in whole minutes):");
         checkForValidMinsToReCharge(Console.ReadLine());
     }
 }
        /**
         * This method gets the owners name
         */
        private string getOwnerName()
        {
            string ownerName = "";

            ConsoleUtils.ClearConsoleAndWrite("Enter the owners name of the vehicle");
            ownerName = Console.ReadLine();
            ownerName = ConsoleUtils.CheckStringInput(ownerName, "Owners Name");

            return(ownerName);
        }
        /**
         * This method gets the owners phone number
         */
        private string getOwnerPhoneNum(string i_OwnerName)
        {
            string ownerPhoneNum = "";

            ConsoleUtils.ClearConsoleAndWrite(string.Format("Enter {0}'s phone number", i_OwnerName));
            ownerPhoneNum = Console.ReadLine();
            ownerPhoneNum = "" + ConsoleUtils.CheckIntInput(ownerPhoneNum, "Phone number");

            return(ownerPhoneNum);
        }
        /**
         * This method gets the name of the wheels manufacturer
         */
        private void getWheelManufacturer(List <Wheel> i_WheelList)
        {
            ConsoleUtils.ClearConsoleAndWrite("Enter the manufacturer of the wheels");
            string wheelManufacturer = ConsoleUtils.CheckStringInput(Console.ReadLine(), "Wheel manufacturer");

            foreach (Wheel wheel in i_WheelList)
            {
                wheel.ManufactureName = wheelManufacturer;
            }
        }
        /**
         * This method validates the amount of time to recharge in min.
         */
        private void checkForValidMinsToReCharge(string i_userInput)
        {
            string minsToChargeStr = i_userInput;

            while (!int.TryParse(minsToChargeStr, out this.m_MinsToCharge))
            {
                ConsoleUtils.ClearConsoleAndWrite("Invalid number of minutes to charge");
                Console.WriteLine("Please enter a valid amount of minutes to charge:");
                minsToChargeStr = Console.ReadLine();
            }
        }
Beispiel #11
0
        /**
         * This method checks for a valid answer by the user for the filter question.
         */
        private string checkForValidAnswer(string i_userInput)
        {
            string userInput = i_userInput;

            while (!userInput.Equals("y") && !userInput.Equals("n"))
            {
                ConsoleUtils.ClearConsoleAndWrite("Invalid Input! Please enter y for yes and n for no");
                userInput = Console.ReadLine();
            }

            return(userInput);
        }
 /**
  * This method changes the vehicle status.
  */
 public void ChangeStatus()
 {
     getDetailsForStatusChange();
     try
     {
         r_Garage.ChangeVehicleStatus(m_LicenseNumber, m_NewVehicleStatus);
         ConsoleUtils.ClearConsoleAndWrite("Changed the status of the vehicle successfully");
         ConsoleUtils.PressAnyKeyToContinue();
     }
     catch (Exception e)
     {
         ConsoleUtils.ClearConsoleAndWrite(e.Message);
         ConsoleUtils.PressAnyKeyToContinue();
     }
 }
 /**
  * This method recharges the vehicle.
  * Prints an error according to the error.
  */
 public void Recharge()
 {
     try
     {
         getDetailsForRecharge();
         r_Garage.RechargeVehicle(m_LicenseNumber, m_MinsToCharge / 60);
         string chargingMessage = m_CheckForEnergyType ? "Vehicle was charged successfully" : "Vehicle can't be charged";
         ConsoleUtils.ClearConsoleAndWrite(chargingMessage);
         ConsoleUtils.PressAnyKeyToContinue();
     }
     catch (Exception e)
     {
         ConsoleUtils.ClearConsoleAndWrite(e.Message);
         ConsoleUtils.PressAnyKeyToContinue();
     }
 }
Beispiel #14
0
        /**
         * This method checks for a valid eVehicleGarageStatus
         */
        private Vehicle.eVehicleGarageStatus checkForValidVehicleGarageStatus(string i_userInput)
        {
            string userInput = i_userInput;
            int    userInputAsInt;

            while (!((int.TryParse(userInput, out userInputAsInt) && (Enum.IsDefined(typeof(Vehicle.eVehicleGarageStatus), userInputAsInt)))))
            {
                ConsoleUtils.ClearConsoleAndWrite(@"Invalid Input! The filters are:
1.In repair 
2.Repaired 
3.Payed for");
                userInput = Console.ReadLine();
            }

            return((Vehicle.eVehicleGarageStatus)userInputAsInt);
        }
        /**
         * This method validates the vehicle status.
         */
        private Vehicle.eVehicleGarageStatus checkForValidVehicleStatus(string i_UserInput)
        {
            string userInput = i_UserInput;
            int    userInputAsInt;

            while (!(int.TryParse(userInput, out userInputAsInt) && (Enum.IsDefined(typeof(Vehicle.eVehicleGarageStatus), userInputAsInt))))
            {
                ConsoleUtils.ClearConsoleAndWrite("Invalid status, please enter a valid status");
                Console.WriteLine(@"1.In repair,
2.Repaired,
3.Payed for");
                userInput = Console.ReadLine();
            }

            return((Vehicle.eVehicleGarageStatus)userInputAsInt);
        }
Beispiel #16
0
        /**
         * This method validates the fuel type.
         */
        private Fuel.eFuelType checkForValidFuelType(string i_UserInput)
        {
            string userInput = i_UserInput;
            int    userInputAsInt;

            while (!(int.TryParse(userInput, out userInputAsInt) && Enum.IsDefined(typeof(Fuel.eFuelType), userInputAsInt)))
            {
                ConsoleUtils.ClearConsoleAndWrite("Invalid fuel type, please enter a valid type");
                Console.WriteLine(@"1. Soler
2. Octan95
3. Octan96
4. Octan98");
                userInput = Console.ReadLine();
            }

            return((Fuel.eFuelType)userInputAsInt);
        }
 /**
  * This method is inflate the air to max.
  */
 public void Inflate()
 {
     getLicenseNumber();
     try
     {
         r_Garage.InflateWheelToMax(m_LicenseNumber);
         ConsoleUtils.ClearConsoleAndWrite("Inflated all the wheels successfully");
         Console.WriteLine("Press any key to continue");
         Console.ReadLine();
     }
     catch (Exception e)
     {
         ConsoleUtils.ClearConsoleAndWrite(e.Message);
         Console.WriteLine("Press any key to continue");
         Console.ReadLine();
     }
 }
Beispiel #18
0
        /**
         * This method asks refueling details.
         */
        private void getDetailsForRefuel()
        {
            ConsoleUtils.ClearConsoleAndWrite("Please enter the license number of the vehicle you would like to refuel:");
            this.m_LicenseNumber = ConsoleUtils.CheckForValidLicenseNumber(Console.ReadLine());
            //checks that the energy types match
            if (m_CheckForEnergyType = checkEnergyType(m_LicenseNumber))
            {
                ConsoleUtils.ClearConsoleAndWrite("Please enter the amount of fuel you would like to refuel:");
                checkForValidAmountOfFuel(Console.ReadLine());
                ConsoleUtils.ClearConsoleAndWrite("Please enter the type of fuel type of the vehicle:");
                Console.WriteLine(@"1. Soler
2. Octan95
3. Octan96
4. Octan98");
                this.m_FuelType = checkForValidFuelType(Console.ReadLine());
            }
        }
Beispiel #19
0
 /**
  * This method refuels the vehicle.
  * Prints an error according to the error.
  */
 public void Refuel()
 {
     try
     {
         getDetailsForRefuel();
         r_Garage.RefuelVehicle(m_LicenseNumber, m_FuelType, m_AmountForFuel);
         string refuelingMessage = m_CheckForEnergyType
             ? "Refueled the vehicle successfully"
             : "Vehicle cannot be refueled";
         ConsoleUtils.ClearConsoleAndWrite(refuelingMessage);
         ConsoleUtils.PressAnyKeyToContinue();
     }
     catch (Exception e)
     {
         ConsoleUtils.ClearConsoleAndWrite(e.Message);
         ConsoleUtils.PressAnyKeyToContinue();
     }
 }
        /**
         * This method gets the vehicles current amount of energy.
         */
        private void getCurrentAmountOfEnergy(EnergySource i_EnergySource)
        {
            string message = (i_EnergySource is Fuel) ? "fuel amount" : "battery time left (in hours)";

            ConsoleUtils.ClearConsoleAndWrite(string.Format("Enter the current {0}", message));
            string userInput      = Console.ReadLine();
            float  convertedInput = ConsoleUtils.CheckFloatInput(userInput, "Energy amount");

            try
            {
                i_EnergySource.RefuelEnergy(convertedInput);
            }
            catch (Exception e)
            {
                ConsoleUtils.ClearConsoleAndWrite(e.Message);
                Console.WriteLine("Press any key to continue");
                Console.ReadLine();
                getCurrentAmountOfEnergy(i_EnergySource);
            }
        }
        /**
         * This method updates the relevant vehicles information.
         * Returns the updates vehicle.
         */
        public Vehicle GetUniqueInfo(Vehicle i_Vehicle)
        {
            List <object> userInputAnswers = new List <object>();

            for (int i = 0; i < i_Vehicle.UniqueInfoList.Count; i++)
            {
                VehicleUniqueInfo information = i_Vehicle.UniqueInfoList[i];
                string            message     = (information.Type == typeof(bool))
                    ? "Please Enter y (yes) if {0} or n (no) if not."
                    : "Enter the {0}";
                ConsoleUtils.ClearConsoleAndWrite(string.Format(message, information.Message));
                if (information.Type.IsEnum)
                {
                    ConsoleUtils.PrintEnum(information.Type);
                }

                string userInput = Console.ReadLine();
                try
                {
                    checkUserInformationInput(userInput, information);
                    if (information.Type == typeof(bool))
                    {
                        userInputAnswers.Add(userInput.Equals("y"));
                    }
                    else
                    {
                        userInputAnswers.Add(userInput);
                    }
                }
                catch (FormatException fe)
                {
                    ConsoleUtils.ClearConsoleAndWrite(fe.Message);
                    ConsoleUtils.PressAnyKeyToContinue();
                    i--;
                }
            }

            i_Vehicle.UpdateUniqueFields(userInputAnswers);

            return(i_Vehicle);
        }
        /**
         * This methods gets the current wheel pressure from the user
         */
        private void getCurrentWheelPressure(List <Wheel> i_Wheels)
        {
            ConsoleUtils.ClearConsoleAndWrite("Enter the current pressure of the wheels");
            string userInput            = Console.ReadLine();
            float  convertedAirPressure = ConsoleUtils.CheckFloatInput(userInput, "Tire Pressure");

            try
            {
                foreach (Wheel wheel in i_Wheels)
                {
                    wheel.Inflate(convertedAirPressure);
                }
            }
            catch (ValueOutOfRangeException voore)
            {
                ConsoleUtils.ClearConsoleAndWrite(voore.Message);
                Console.WriteLine("Press any key to continue");
                Console.ReadLine();
                getCurrentWheelPressure(i_Wheels);
            }
        }
Beispiel #23
0
        /**
         * This method prints a list of license numbers in the garage.
         */
        public void PrintGarageLicenseNumberList()
        {
            ConsoleUtils.ClearConsoleAndWrite("Would you like to filter the list by vehicle status? enter y / n");
            string needForFilter = checkForValidAnswer(Console.ReadLine());

            if (needForFilter.Equals("y"))
            {
                ConsoleUtils.ClearConsoleAndWrite("Please enter a valid number for a filter.");
                Console.WriteLine(@"The filters are:
1.In repair 
2.Repaired 
3.Payed for");
                Vehicle.eVehicleGarageStatus filter = checkForValidVehicleGarageStatus(Console.ReadLine());
                printList(r_Garage.GetLicenseList(filter));
            }
            else if (needForFilter.Equals("n"))
            {
                printList(r_Garage.GetLicenseList(null));
            }

            ConsoleUtils.PressAnyKeyToContinue();
        }
        /**
         * This method gets the vehicles details from user
         * Catches ArgumentException
         */
        public Vehicle GetVehicleDetailsFromUser()
        {
            Vehicle vehicleToAdd = null;

            try
            {
                vehicleToAdd = VehicleBuilder.MakeVehicle(getVehicleType());
                vehicleToAdd.LicenseNumber = getLicenseNumber();
                r_Garage.AddVehicleToGarage(vehicleToAdd);
                vehicleToAdd = fillDetails(vehicleToAdd);
                ConsoleUtils.ClearConsoleAndWrite("Vehicle added successfully!");
                Console.WriteLine("Press any key to continue");
                Console.ReadLine();
            }
            catch (ArgumentException ae)
            {
                ConsoleUtils.ClearConsoleAndWrite(ae.Message);
                Console.WriteLine("Press any key to continue");
                Console.ReadLine();
            }

            return(vehicleToAdd);
        }
 /**
  * This method gets the vehicle license number.
  */
 private void getLicenseNumber()
 {
     ConsoleUtils.ClearConsoleAndWrite("Please enter the license number of the vehicle");
     this.m_LicenseNumber = ConsoleUtils.CheckForValidLicenseNumber(Console.ReadLine());
 }