public void processQueue(int time, Simulator sim) throws VehicleException,
			SimulationException {
		archiveQueueFailures(time);

		final int tempQueueSize = vehiclesInQueue.size();
		Vehicle v;
		endLoop: for (int i = 0; i < tempQueueSize; i++) {

			v = vehiclesInQueue.get(0);
			if (!v.isQueued()) {
				throw new VehicleException("The vehicle is not in queue.");
			} else if (time < 0) {
				throw new VehicleException("Time cannot be negative.");
			} else if (v.getArrivalTime() > Constants.CLOSING_TIME) {
				throw new VehicleException("Carpark is closed.");
			}

			// If there is an available space, park the vehicle.
			else if (spacesAvailable(v)) {
				if (!spacesAvailable(v)) {
					throw new SimulationException("No suitable parking places.");
				}

				exitQueue(v, time);
				parkVehicle(v, time, sim.setDuration());

				if (v instanceof Car) {
					if (((Car) v).isSmall()) {
						carParkStatus += "|S:Q>P|";
					} else {
						carParkStatus += "|C:Q>P|";
					}
				} else {
					carParkStatus += "|M:Q>P|";
				}

			} else {
				break endLoop;
			}
		}
	}