示例#1
0
        public void refuelGasVehicle()
        {
            m_UserDisplay.ClearAndDisplayMessage("You have chosen to refuel a gas type vehicle");
            string licenseNumber = m_RefuelGasVehicle.GetLicenseNumberForRefuel();

            Gas.eFuelType fuelType     = m_RefuelGasVehicle.GetFuelTypeForRefuel();
            float         amountOfFuel = m_RefuelGasVehicle.GetAmountOfLitersToFuel();

            try
            {
                m_Garage.RefuelGasVehicle(licenseNumber, fuelType, amountOfFuel);
                m_UserDisplay.ClearAndDisplayMessage(string.Format("Vehicle with license number: {0}, was refueled with gas type: {1}, and amount: {2} successfuly!", licenseNumber, fuelType, amountOfFuel));
                m_UserDisplay.PressAnyKeyToContinue();
            }
            catch (Exception exception)
            {
                m_UserDisplay.ClearAndDisplayMessage(exception.Message);

                if (exception is ValueOutOfRangeException)
                {
                    m_UserDisplay.DisplayMessage("Please try again");
                    refuelGasVehicle();
                }
                else
                {
                    m_UserDisplay.PressAnyKeyToContinue();
                }
            }
        }
示例#2
0
        private void getDetailsAndRefuel()
        {
            Console.WriteLine("Please enter the license number of the vehicle you would like to refuel");
            string licenseNumber = ValidateUserInput.ValidateInputInNotEmpty();

            Console.Clear();
            Console.WriteLine("Please enter the type of fuel of the vehicle you would like to refuel");
            Gas.eFuelType fuelType = (Gas.eFuelType)ValidateUserInput.InputIsInRangeOfEnum(typeof(Gas.eFuelType));
            Console.Clear();
            Console.WriteLine("Please enter the amount of fuel you would like to refuel");
            float amountOfFuel = ValidateUserInput.ParseInputToFloat();

            try
            {
                m_UserInterface.Garage.RefuelGasVehicle(licenseNumber, fuelType, amountOfFuel);
                Console.Clear();
                Console.WriteLine(String.Format("Vehicle with license number: {0}, was refueled with gas type: {1}, and amount: {2} successfuly!", licenseNumber, fuelType, amountOfFuel));
                Messages.PressAnyKeyToContinue();
            }
            catch (Exception exception)
            {
                Console.Clear();
                Console.WriteLine(exception.Message);

                if (exception is ValueOutOfRangeException)
                {
                    Console.WriteLine("Please try again");
                    getDetailsAndRefuel();
                }
                else
                {
                    Messages.PressAnyKeyToContinue();
                }
            }
        }
示例#3
0
 public Truck(
     string i_modelName,
     string i_LicenseNumber,
     string i_VehicleType,
     Gas.eFuelType i_fuelType,
     string i_CurrentAmountEnergy,
     string i_WheelManufactor,
     string i_WheelsAirPressure)
     : base(
         i_modelName,
         i_LicenseNumber,
         k_NumOfWheels,
         k_MaxAirPressure,
         i_VehicleType,
         i_fuelType,
         i_CurrentAmountEnergy,
         k_MaxAmountOfFuel,
         i_WheelManufactor,
         i_WheelsAirPressure)
 {
     if (m_EnergySource is Electric)
     {
         throw new ArgumentException("Error: truck can only have gas engine.");
     }
 }
示例#4
0
文件: Electric.cs 项目: Ziv3r/Garage-
        public override void FillEnergy(float i_AmountToFillUp, Gas.eFuelType i_Type = Gas.eFuelType.None)
        {
            if (i_AmountToFillUp + m_Amount > r_Capacity)
            {
                throw new ValueOutOfRangeException(0, r_Capacity - m_Amount);
            }

            m_Amount += i_AmountToFillUp;
        }
示例#5
0
文件: Vehicle.cs 项目: Ziv3r/Garage-
        public Vehicle(
            string i_modelName,
            string i_LicenseNumber,
            int i_NumberOfWheels,
            float i_MaxAirPreasure,
            string i_VehicleType,
            Gas.eFuelType i_fuelType,
            string i_CurrentAmountEnergy,
            float i_TotalAmountOfEnergy,
            string i_WheelManufactor,
            string i_WheelAirPressure)
        {
            r_ModelName     = i_modelName;
            r_LicenseNumber = i_LicenseNumber;
            float currAmountOfEnergy = -1f;
            float currAirPressure;

            EnergySource.eEnergySourceType type;
            try
            {
                currAmountOfEnergy = float.Parse(i_CurrentAmountEnergy);
                type = (EnergySource.eEnergySourceType)Enum.Parse(typeof(EnergySource.eEnergySourceType), i_VehicleType);
            }
            catch (Exception ex)
            {
                throw new FormatException(
                          string.Format(
                              "Error: The field \"{0}\" was not in the right format",
                              currAmountOfEnergy == -1 ? "Fuel Amount" : "Engine Type"),
                          ex);
            }

            if (!float.TryParse(i_WheelAirPressure, out currAirPressure) || currAirPressure > i_MaxAirPreasure)
            {
                throw new FormatException(string.Format("Error: could not assign {0} as current air pressure", i_WheelAirPressure));
            }

            if (type == EnergySource.eEnergySourceType.Gas)
            {
                m_EnergySource = new Gas(currAmountOfEnergy, i_TotalAmountOfEnergy, i_fuelType);
            }
            else
            {
                m_EnergySource = new Electric(currAmountOfEnergy, i_TotalAmountOfEnergy);
            }

            m_VehicleWheels = new List <Wheel>();
            for (int i = 0; i < i_NumberOfWheels; i++)
            {
                m_VehicleWheels.Add(new Wheel(i_MaxAirPreasure, i_WheelManufactor, currAirPressure));
            }
        }
示例#6
0
文件: Vehicle.cs 项目: Ziv3r/Garage-
 public void FillEnergy(string i_Amount, string i_FuelType = "None")
 {
     try
     {
         string        formatedFuelType = char.ToUpper(i_FuelType[0]) + i_FuelType.Substring(1);
         float         amount           = float.Parse(i_Amount);
         Gas.eFuelType type             = (Gas.eFuelType)Enum.Parse(typeof(Gas.eFuelType), formatedFuelType);
         amount = type == Gas.eFuelType.None ? amount / 60 : amount; // user provide amount in minutes. amount saved in hours
         m_EnergySource.FillEnergy(amount, type);
     }
     catch (FormatException ex)
     {
         throw new ArgumentException(
                   string.Format(
                       "Error: \"{0}\" is not a valid type of feul, " +
                       "or \"{1}\" is not a valid amount",
                       i_FuelType),
                   ex);
     }
 }
示例#7
0
 public Motorcycle(
     string i_ModelName,
     string i_LicenseNumber,
     string i_VehicleType,
     Gas.eFuelType i_FuelType,
     string i_CurrentAmountEnergy,
     float i_TotalAmountOfEnergy,
     string i_WheelManufactor,
     string i_CurrAirPressure)
     : base(
         i_ModelName,
         i_LicenseNumber,
         k_NumOfWheels,
         k_MaxAirPressure,
         i_VehicleType,
         i_FuelType,
         i_CurrentAmountEnergy,
         i_TotalAmountOfEnergy,
         i_WheelManufactor,
         i_CurrAirPressure)
 {
 }
示例#8
0
 public abstract void FillEnergy(float i_AmountToFillUp, Gas.eFuelType i_Type);