public void ChargeBatteryByLicense(string i_LicenseNumber, float i_BatteryTimeToAdd) { Electric electricEngine = this[i_LicenseNumber].Engine as Electric; if (electricEngine != null) { electricEngine.ChargeBattery(i_BatteryTimeToAdd); this[i_LicenseNumber].UpdateEnergyPercent(); } else { throw new ArgumentException("The vehicle engine is not from electric type"); } }
public bool ChargeElectricBattery(string i_LicenseNumber, float io_MinutesToAdd) { //// Gets car's license number and minutes of electricity to add. //// Charge the car if minutes is not above max. //// Return T/F if charge succeeded. bool isFilled = false; if (isExist(i_LicenseNumber)) { if (r_Vehicles[i_LicenseNumber].VehicleStatus.Equals(eServiceStatuses.InRepair)) { if (r_Vehicles[i_LicenseNumber].Vehicle.EnergyType is Electric) { Electric currEngine = r_Vehicles[i_LicenseNumber].Vehicle.EnergyType as Electric; isFilled = currEngine.ChargeBattery(io_MinutesToAdd / 60f); if (isFilled) { float percent = currEngine.HoursLeftInBattery / currEngine.MaxHoursInBattery; r_Vehicles[i_LicenseNumber].Vehicle.PercentagesOfEnergyRemaining = percent * 100f; } } else { throw new FormatException("The vehicle engine is not electric!"); } } else { throw new ArgumentException("The vehicle is not 'In-Repair' status. You can not work on this vehicle."); } } return(isFilled); }