// Removes a Vehicle from the list of Vehicles // // takes argument: string regNr - the registration number for the vehicle // returns a string with the return message of the method public string VehicleCheckout(string regNr) { var vehicle = GetVehicle(regNr); if (vehicle == null) { return($"No vehicle found with the reigstration number: {regNr}."); } ParkingSpot index = vehicle.parkingSpot; // Free the occupied parking spaces for (int i = 0; i < vehicle.vehicleSize; i++) { m_ParkingSpaces[index.X, index.Y + i] = !m_ParkingSpaces[index.X, index.Y + i]; } m_Vehicles = m_Vehicles.Where(v => v.regNr != regNr).ToList(); // remove the vehicle from the list; string receipt = $"Total hours parked: {GetTotalHours(vehicle)} and total price: {GetTotalPrice(vehicle)}."; m_Receipts.Add(receipt); return($"The vehicle with the registration number: {regNr} " + $"left the garage, freeing up the parking space(s) {index.ToString()}" + (vehicle.vehicleSize > 1 ? $" to [{index.X + 1},{index.Y + vehicle.vehicleSize}].\n" : ".\n") + receipt); }
// Adds a new Vehicle to the list of Vehicles // Creates a new Vehicle instance and assigns it a free parking space if available // takes no arguments // returns a string with the return message of the method public string ParkNewVehicle() { // Checks if the garage is full, so we can exit earlier if the garage is full if (NumberOfParkingSpaces == m_Vehicles.Count) { return($"The garage is full."); } // Get the current date string dateNow = GetDate(); // the new vehicle to be added Vehicle vehicle = GenerateRandomVehicle(); // Redundant since this is being checked in the method that generates a random vehicle, but I'll leave it in here anyway if (GetVehicle(vehicle.regNr) != null) { return($"A vehicle with the registration number: {vehicle.regNr} is already parked in the garage!"); } // so we can exit earlier if there's not enough space in the garage if (GetNumberOfFreeSpaces() < vehicle.vehicleSize) { return($"The garage is full!!."); } ParkingSpot index = FindFreeParkingSpace(vehicle.vehicleSize); // index used to find empty parking space // checks if we found a free parking space for the type of vehicle if (index.X == -1 && index.Y == -1) { return($"Not enough empty spaces in the garage for a vehicle of type: { vehicle.vehicleType.ToString()}."); } // sets the found parking space(s) to occupied/true for (int i = 0; i < vehicle.vehicleSize; i++) { m_ParkingSpaces[index.X, index.Y + i] = !m_ParkingSpaces[index.X, index.Y + i]; } // assigns the vehicle its parking space vehicle.parkingSpot = index; // add the new vehicle to the list m_Vehicles.Add(vehicle); return($"The vehicle of the type: {vehicle.vehicleType.ToString()} " + $"with the registration number: {vehicle.regNr} \nwas parked in the garage at " + $"parking space(s): {index.ToString()}" + (vehicle.vehicleSize > 1 ? $" to [{index.X + 1},{index.Y + vehicle.vehicleSize}]." : "")); }
// !Mainly used for manual testing with different vehicle types! // Adds a new Vehicle to the list of Vehicles - // Creates a new Vehicle instance and assigns it a free parking space if available // takes argument v_Vehicle - type of vehicle to be created // returns a string with the return message of the method public string ParkVehicle(v_Vehicle type) { // Checks if the garage is full, so we can exit earlier if the garage is full if (NumberOfParkingSpaces == m_Vehicles.Count) { return($"The garage is full."); } // Get the current date string dateNow = GetDate(); // the new vehicle to be added Vehicle vehicle; // = GenerateRandomVehicle(); switch (type) { case v_Vehicle.Bus: vehicle = new Bus() { regNr = getRandomRegNr(), dateTime = dateNow }; break; case v_Vehicle.Car: vehicle = new Car() { regNr = getRandomRegNr(), dateTime = dateNow }; break; case v_Vehicle.MC: vehicle = new MC() { regNr = getRandomRegNr(), dateTime = dateNow }; break; case v_Vehicle.Truck: vehicle = new Truck() { regNr = getRandomRegNr(), dateTime = dateNow }; break; default: vehicle = null; break; } // so we can exit earlier if there's not enough space in the garage if (GetNumberOfFreeSpaces() < vehicle.vehicleSize) { return($"The garage is full!!."); } ParkingSpot index = FindFreeParkingSpace(vehicle.vehicleSize); // index used to find empty parking space // checks if we found a free parking space for the type of vehicle if (index.X == -1 && index.Y == -1) { return($"Not enough empty spaces in the garage for a vehicle of type: { vehicle.vehicleType.ToString()}."); } // sets the found parking space(s) to occupied/true for (int i = 0; i < vehicle.vehicleSize; i++) { m_ParkingSpaces[index.X, index.Y + i] = !m_ParkingSpaces[index.X, index.Y + i]; } // assigns the vehicle its parking space vehicle.parkingSpot = index; // add the new vehicle to the list m_Vehicles.Add(vehicle); return($"The vehicle of the type: {vehicle.vehicleType.ToString()} " + $"with the registration number: {vehicle.regNr} \nwas parked in the garage at " + $"parking space(s): {index.ToString()}" + (vehicle.vehicleSize > 1 ? $" to [{index.X + 1},{index.Y + vehicle.vehicleSize}]." : "")); }