/// <summary> /// Finds a vehicle with a distinct registration number. /// </summary> /// <param name="parkingPlace"></param> /// <param name="registrationNumber"></param> /// <returns>Position of the found vehicle. -1 if not found</returns> public static int FindDistinct(string[] parkingPlace, string registrationNumber) { for (int i = 0; i < parkingPlace.Length; i++) { // Try to find motorcycle if (ParkingSlot.ContainsMc(parkingPlace[i], registrationNumber)) { // Mc found return(i); } else if (parkingPlace[i] == null) { // empty parking place. Do nothing. } else { // try to find a car string CarRegNr = null; int indexOfRegNrDateSeparator = parkingPlace[i].IndexOf(','); if (indexOfRegNrDateSeparator > -1) { CarRegNr = ParkingSlot.GetRegistrationNumber(parkingPlace[i]); } // Try to find car if (registrationNumber == CarRegNr) { // Car found return(i); } } } //Your Vehicle is not found return(-1); }
/// <summary> /// remove the vehicle /// </summary> /// <param name="parkingSlot"></param> /// <param name="registrationNumber"></param> public static void RemoveVehicle(ref string parkingSlot, string registrationNumber) { VehicleType type = ParkingSlot.GetVehicleTypeOfParkedVehicle(parkingSlot, registrationNumber); if (type == VehicleType.Car) { if (ParkingSlot.GetRegistrationNumber(parkingSlot) == registrationNumber) { // Setting to null tells its empty parkingSlot = null; } else { throw new VehicleNotFoundException(); } } else if (type == VehicleType.Mc) { // Remove Mc RemoveMc(ref parkingSlot, registrationNumber); } }