import java.util.*;

public class Rules
{
    public static final String BAGS = "bags";
    public static final String BAGS_CONTAINS = "bags contain";
    public static final String NO_BAGS = " no other bags";
    public static final String CONTAINS = "contain";
    public static final String SEPARATOR = ",";
    public static final String TERMINATOR = ".";
    public static final String SPACE = " ";

    public Rules (boolean debug)
    {
        _debug = debug;
    }

    public Inventory parse (String dataFile)
    {
        Vector<String> rules = Util.loadData(dataFile, _debug);
        Inventory inv = new Inventory(_debug);
        Enumeration<String> iter = rules.elements();
        boolean error = false;

        while (iter.hasMoreElements() && !error)
        {
            String line = iter.nextElement();
            int startIndex = line.indexOf(BAGS_CONTAINS);  // name of bag

            if (startIndex != -1)
            {
                String bagColour = line.substring(0, startIndex);
                Bag theBag = new Bag(bagColour);

                inv.add(theBag);

                String remainder = line.substring(startIndex + BAGS_CONTAINS.length());

                if (!remainder.equals(NO_BAGS))
                {
                    boolean finished = false;

                    startIndex = 0;

                    while (!finished)
                    {
                        int endIndex = remainder.indexOf(Rules.SEPARATOR, startIndex);

                        if (startIndex != -1)
                        {
                            int spaceIndex = remainder.indexOf(Rules.SPACE, startIndex);
                            String number = remainder.substring(startIndex, spaceIndex);
                        }
                    }
                }
            }
            else
            {
                System.out.println("Error, no bag name found!");

                error = true;
            }
        }

        return inv;
    }

    private boolean _debug;
}
@@ -1055,24 +1055,116 @@
 agColour);%0A%0A
+                if (_debug)%0A                    System.out.println(%22Loading bag %22+theBag);%0A%0A
             
@@ -1592,37 +1592,35 @@
             if (
-start
+end
 Index != -1)%0A   
@@ -1674,66 +1674,192 @@
     
-int spaceIndex = remainder.indexOf(Rules.SPACE, start
+Bag contains = containsBag(remainder, startIndex, endIndex);%0A%0A                            theBag.add(contains);%0A%0A                            remainder = remainder.substring(end
 Index
+ +1
 );%0A 
@@ -1885,48 +1885,194 @@
     
-    String number = remainder.substring(
+%7D%0A                        else%0A                        %7B%0A                            endIndex = remainder.length() -1;%0A%0A                            Bag contains = containsBag(remainder, 
 star
@@ -2083,20 +2083,115 @@
 ex, 
-space
+end
 Index);
+%0A%0A                            theBag.add(contains);%0A%0A                            finished = true;
 %0A   
@@ -2442,24 +2442,435 @@
 inv;%0A    %7D%0A%0A
+    private Bag containsBag (String data, int startIndex, int endIndex)%0A    %7B%0A        int spaceIndex = data.indexOf(Rules.SPACE, startIndex);%0A        String number = data.substring(startIndex, spaceIndex);%0A        int quantity = Integer.parseInt(number);%0A        String bagType = data.substring(spaceIndex +1, endIndex);%0A        Bag containsBag = new Bag(bagType, quantity);%0A%0A        return containsBag;%0A    %7D%0A%0A
     private 

Update Rules.java