import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; import java.io.FileInputStream; import java.io.FileNotFoundException; /** State.java - Let's just collect our list of schools into an aggregate * called State. The constructor reads the school info, one school per line. * We'll create a school object and add it to our ArrayList called list. * The sort() function calls the special Collections.sort, which requires * a comparator object. */ public class State { private ArrayList list; public State() throws FileNotFoundException { list = new ArrayList(); Scanner inFile = new Scanner(new FileInputStream("sc.txt")); while (inFile.hasNextLine()) { String line = inFile.nextLine(); School sch = new School(line); list.add(sch); } } public void sort() { Collections.sort(list, new SchoolComparator()); } public String toString() { StringBuilder build = new StringBuilder(); for (int i = 0; i < list.size(); ++i) build.append(list.get(i) + "\n"); return build.toString(); } }