// TODO: Return a list of all passengers that get dropped off public void drive() { location++; int i = 0; while (i < passengers.size()) { Person p = passengers.get(i); if (p.getDestination() == location) { passengers.remove(i); // TODO: Remove print statement System.out.println(driverName + " drops off " + p.getName()); } else { i++; } } }
/** * Tries to add a passenger. * * @param p the new passenger * @return true if there is room in the car and the passenger's destination on the way to this * car's destination */ public boolean tryToAdd(Person p) { if (passengers.size() + 2 <= numberOfSeats && p.getDestination() <= destination) { passengers.add(p); return true; } else { return false; } }