import java.util.Scanner; import java.util.ArrayList; import java.io.PrintWriter; import java.io.FileReader; class Caravan { String dest; ArrayList cars = new ArrayList(); Caravan(String filename) { Scanner file = null; try { file = new Scanner(new FileReader(filename)); } catch (Exception e) { e.printStackTrace(); System.exit(2); } this.dest = file.nextLine(); try { while (true) { Car c = new Car(file); this.cars.add(c); } } catch (NoCarException e) { // this is actually a happy state :) } } Caravan() { } void addCar(Car aCar) { this.cars.add(aCar); } void setDest(String dest) { this.dest = dest; } void persist(PrintWriter pw) { pw.println(this.dest); for (int i=0; i< cars.size(); i++) { Car nextCar = cars.get(i); nextCar.persist(pw); } pw.println("Done with cars."); pw.flush(); } public String toString() { String retval = ""; retval += "A caravan going to " + this.dest + "\n"; retval += "Here are my cars: \n"; for (int i=0; i