import java.util.Scanner; import java.util.Iterator; import java.io.FileNotFoundException; import java.io.FileInputStream; /** Driver.java - Let's experiment with the Bag data structure we just * created. The input file, e.g. candy.txt, should be specified * at the command line. So run it this way: java Driver candy.txt */ public class Driver { public static void main(String [] args) throws FileNotFoundException { Scanner inFile = new Scanner(new FileInputStream(args[0])); BagArrayList bag = new BagArrayList(); // read the input file to intialize the bag while (inFile.hasNextLine()) { String name = inFile.nextLine(); if (name == null) break; bag.add(new Item(name)); } // Now dump out the contents of the bag, using the iterator Iterator it = bag.bagIterator(); while (it.hasNext()) System.out.println("Eating a(n) " + it.next()); } }