Ejemplo n.º 1
0
        public bool FuelVehicle(string i_PlateNumber, float i_Amount, FuelEngine.eFuelType i_Type)
        {
            bool           isFueled = false;
            GarageCustomer customer = FindCustomerByPlateNumber(i_PlateNumber);

            if (customer != null)
            {
                IEngine engine = customer.Vehicle.Engine;
                if (engine.EngineType() == typeof(FuelEngine))
                {
                    FuelEngine fuelEngine = (FuelEngine)engine;
                    if (i_Type.Equals(fuelEngine.FuelType))
                    {
                        isFueled = fuelEngine.PutGas(i_Amount);
                    }
                    else
                    {
                        throw new ArgumentException("Wrong type of fuel");
                    }
                }
                else
                {
                    throw new ArgumentException("Trying to put gas in an electric engine");
                }
            }

            return(isFueled);
        }
Ejemplo n.º 2
0
        public bool ChargeVehicle(string i_PlateNumber, float i_Amount)
        {
            bool isCharged = false;

            GarageCustomer customer = FindCustomerByPlateNumber(i_PlateNumber);

            if (customer == null)
            {
                return(false);
            }
            IEngine engine = customer.Vehicle.Engine;

            if (engine.EngineType() == typeof(ElectricEngine))
            {
                ElectricEngine electricEngine = (ElectricEngine)engine;

                isCharged = electricEngine.chargeBattery(i_Amount);
            }
            else
            {
                throw new ArgumentException("Trying to put gas in an electric engine");
            }

            return(isCharged);
        }
Ejemplo n.º 3
0
        // 5 Method- The method refuel vehicle on gas
        public void Refuel(string i_LicenseNumber, eGasType i_FuelType, float i_FuelToAdd)
        {
            GarageCustomer customer = FindVehicleInGarage(i_LicenseNumber);
            GasTank        gasTank  = customer.Vehicle.GasTank;


            if (gasTank != null)
            {
                if (!gasTank.GasType.ToString().Equals(i_FuelType.ToString()))
                {
                    throw new ArgumentException("Wrong fuel type"); // throw wrong gas exception.
                }

                else
                {
                    if (i_FuelToAdd < 0 || i_FuelToAdd > gasTank.MaxCapacity - gasTank.CurrentAmount)
                    {
                        throw new ValueOutOfRangeException(gasTank.MaxCapacity - gasTank.CurrentAmount, 0);
                    }

                    else
                    {
                        gasTank.CurrentAmount      += i_FuelToAdd;
                        customer.Vehicle.EnergyLeft = gasTank.CurrentAmount / gasTank.MaxCapacity;
                    }
                }
            }
            else
            {
                throw new ArgumentException("Cannot refuel with gas an electric vehicle");
            }
        }
Ejemplo n.º 4
0
        // 4 Method - Inflate wheels to max
        public void InflateToMax(string i_LicenseNumber)
        {
            GarageCustomer customer        = FindVehicleInGarage(i_LicenseNumber);
            List <Wheel>   wheelsToInflate = customer.Vehicle.Wheels;

            foreach (Wheel wheel in wheelsToInflate)
            {
                wheel.Inflate(wheel.MaxAirPressure - wheel.CurrentAirPressure); // inflates to the max
            }
        }
Ejemplo n.º 5
0
        // 3 -Method - changes the status of the specific vehicle in the garage - by license plate
        public void ChangeStatus(string i_LicenseNumber, eStatus i_NewStatus)
        {
            GarageCustomer currentCustomer = FindVehicleInGarage(i_LicenseNumber);

            if (currentCustomer != null)
            {
                currentCustomer.Status = i_NewStatus;
            }
            else
            {
                throw new ArgumentException("No such vehicle found");
            }
        }
Ejemplo n.º 6
0
        public bool InflateToMax(string i_PlateNumber)
        {
            bool           result   = false;
            GarageCustomer customer = FindCustomerByPlateNumber(i_PlateNumber);

            if (customer != null)
            {
                foreach (Wheel wheel in customer.Vehicle.Wheels)
                {
                    wheel.InflateToMax();
                }

                result = true;
            }

            return(result);
        }
Ejemplo n.º 7
0
        // 1 -Method - insert a new vehicle to the garage
        public bool InsertVehicle(Vehicle i_Vehicle, string i_OwnerName, string i_PhoneNumber)
        {
            GarageCustomer currentCustomer = FindVehicleInGarage(i_Vehicle.LicenseNumber);

            if (currentCustomer == null)
            {
                currentCustomer             = new GarageCustomer();
                currentCustomer.Vehicle     = i_Vehicle;
                currentCustomer.OwnerName   = i_OwnerName;
                currentCustomer.PhoneNumber = i_PhoneNumber;
                currentCustomer.Status      = eStatus.Repairing;
                CustomersList.Add(currentCustomer);
                return(true);
            }
            else
            {
                currentCustomer.Status = eStatus.Repairing;
                return(false);
            }
        }
Ejemplo n.º 8
0
        // 6 Method- the method recharges the specific vehicle
        public void Recharge(string i_LicenseNumber, float i_TimeToAdd)
        {
            GarageCustomer customer = FindVehicleInGarage(i_LicenseNumber);
            Battery        battery  = customer.Vehicle.Battery;

            if (battery != null)
            {
                if (i_TimeToAdd < 0 || i_TimeToAdd > battery.TimeCapacity)
                {
                    throw new ValueOutOfRangeException(battery.TimeCapacity - battery.TimeLeft, 0);
                }

                else
                {
                    battery.TimeLeft           += i_TimeToAdd;
                    customer.Vehicle.EnergyLeft = battery.TimeLeft / battery.TimeCapacity;
                }
            }
            else
            {
                throw new ArgumentException("Cannot recharge gas vehicle");
            }
        }
Ejemplo n.º 9
0
        public void ChangeStatus(string i_PlateNumber, MotorVehicle.eVehicleStatus i_Status)
        {
            GarageCustomer customer = FindCustomerByPlateNumber(i_PlateNumber);

            customer.Vehicle.Status = i_Status;
        }
Ejemplo n.º 10
0
 public void Add(GarageCustomer i_customer)
 {
     m_Customers.Add(i_customer);
 }
Ejemplo n.º 11
0
 /** A method that compares two customers.
  *  By assumption, we don't support a customer with multiple vehicles,
  *  therefore, two customers will be considered equal if they own the same car
  *
  *  Note that two cars are considered equal according to their plate number.
  *
  */
 public bool Equals(GarageCustomer i_Other)
 {
     return(i_Other.m_Vehicle.Equals(this.m_Vehicle));
 }