import java.util.*;
import java.io.*;

public class Verifier
{
    public static final String EXAMPLE1_FILE = "example1.txt";
    public static final int TOTAL_ORE_1 = 31;
    public static final String EXAMPLE2_FILE = "example2.txt";
    public static final int TOTAL_ORE_2 = 165;
    public static final String EXAMPLE3_FILE = "example3.txt";
    public static final int TOTAL_ORE_3 = 13312;
    public static final String EXAMPLE4_FILE = "example4.txt";
    public static final int TOTAL_ORE_4 = 180697;
    public static final String EXAMPLE5_FILE = "example5.txt";
    public static final int TOTAL_ORE_5 = 2210736;

    public Verifier (boolean debug)
    {
        _debug = debug;
        _theParser = new Parser(debug);
        _oresNeeded = 0;
    }

    /*
     * 10 ORE => 10 A
     * 1 ORE => 1 B
     * 7 A, 1 B => 1 C
     * 7 A, 1 C => 1 D
     * 7 A, 1 D => 1 E
     * 7 A, 1 E => 1 FUEL
     */

    public final boolean verify ()
    {
        Vector<Reaction> reactions = _theParser.loadData(EXAMPLE1_FILE);

        //if (_debug)
        {
            Enumeration<Reaction> iter = reactions.elements();

            while (iter.hasMoreElements())
                System.out.println(iter.nextElement());
        }

        Reaction fuel = findReaction(Chemical.FUEL, reactions);
        Vector<Reactant> inventory = new Vector<Reactant>();

        if (fuel != null)
        {
            boolean completed = false;
            int fuelNeeded = fuel.chemicalCreated().getAmount();
            Vector<Reactant> reactants = fuel.getReactants();    // maybe not all reactions given are needed

            /*
             * Go through each reactant and try to create the
             * required amount, storing excess in the inventory.
             * So check the inventory first, of course.
             */

             Enumeration<Reactant> iter = reactants.elements();

             while (iter.hasMoreElements())
             {
                 Reactant react = iter.nextElement();

                 System.out.println("**got "+react);

                 Reaction r = findReaction(react.getChemical().getName(), reactions);

                 System.out.println("**and "+r);

                 if (r.isOre())
                    System.out.println("ORE");
                else
                    System.out.println("NOT ORE");
             }
        }
        else
            System.out.println("Error! No fuel required?!");
        
        return false;
    }

    private Reaction findReaction (String name, Vector<Reaction> reactions)
    {
        Enumeration<Reaction> iter = reactions.elements();

        while (iter.hasMoreElements())
        {
            Reaction r = iter.nextElement();

            if (r.chemicalCreated().getChemical().getName().equals(name))
                return r;
        }

        return null;
    }

    private int takeFromInventory (Reactant name, Vector<Reactant> inventory, int amountNeeded)
    {
        Enumeration<Reactant> iter = inventory.elements();
        int amount = -1;

        while (iter.hasMoreElements())
        {
            Reactant r = iter.nextElement();

            if (r.getChemical().equals(name.getChemical()))
            {
                int amountFound = r.getAmount();

                if (amountFound > 0)
                {
                    if (amountFound >= amountNeeded)
                        amount = amountNeeded;
                    else
                        amount = amountNeeded - amountFound;

                    r.setAmount(amountFound - amount);
                }
            }
        }

        return amount;
    }

    private boolean _debug;
    private Parser _theParser;
    private int _oresNeeded;
}
@@ -725,33 +725,8 @@
 g);%0A
-        _oresNeeded = 0;%0A
     
@@ -994,16 +994,43 @@
 1_FILE);
+%0A        int oreNeeded = 0;
 %0A%0A      
@@ -2002,63 +2002,8 @@
 ();%0A
-%0A                 System.out.println(%22**got %22+react);%0A%0A
     
@@ -2088,55 +2088,214 @@
 s);%0A
-%0A                 System.out.println(%22**and %22+r
+                 int needed = react.getAmount();%0A%0A                 System.out.println(%22**got %22+react);%0A                 System.out.println(%22**and %22+r);%0A                 System.out.println(%22**needed %22+needed
 );%0A%0A
@@ -2325,24 +2325,40 @@
 isOre())%0A   
+              %7B%0A
             
@@ -2354,32 +2354,35 @@
                 
+   
 System.out.print
@@ -2389,86 +2389,506 @@
 ln(%22
-ORE%22);%0A                else%0A                    System.out.println(%22NOT ORE%22);
+**creates %22+r.chemicalCreated().getAmount());%0A                    int foundInInventory = takeFromInventory(react, inventory, needed);%0A%0A                    System.out.println(%22**found %22+foundInInventory+%22 in inventory%22);%0A                    //oreNeeded += r.getReactants().elementAt(0).getAmount();%0A%0A                    if (foundInInventory %3C needed)%0A                    %7B%0A                        %0A                    %7D%0A                 %7D%0A                 else%0A                 %7B%0A%0A                 %7D
 %0A   
@@ -4236,34 +4236,5 @@
 er;%0A
-    private int _oresNeeded;%0A
 %7D

Update Verifier.java