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

public class Grid
{
    public static final int DEFAULT_WIDTH = 5;
    public static final int DEFAULT_HEIGHT = 5;

    public Grid (String fileName)
    {
        this(DEFAULT_HEIGHT, DEFAULT_WIDTH, fileName);
    }

    public Grid (int height, int width, String fileName)
    {
        _height = height;
        _width = width;

        loadWorld(fileName);
    }

    /**
     * Each minute, The bugs live and die based on the number of bugs in the four adjacent tiles:
     *
     * - A bug dies (becoming an empty space) unless there is exactly one bug adjacent to it.
     * - An empty space becomes infested with a bug if exactly one or two bugs are adjacent to it.
     * 
     * Otherwise, a bug or empty space remains the same. (Tiles on the edges of the grid have fewer than
     * four adjacent tiles; the missing tiles count as empty space.) This process happens in every location
     * simultaneously; that is, within the same minute, the number of adjacent bugs is counted for every tile
     * first, and then the tiles are updated.
     */

    public void evolve ()
    {
        Tile[][] _nextWorld = new Tile[_height][_width];
        
    }

    @Override
    public String toString ()
    {
        String str = "";

        for (int i = 0; i < _height; i++)
        {
            for (int j = 0; j < _width; j++)
                str += _theWorld[i][j];
            
            str += "\n";
        }

        return str;
    }

    private void loadWorld (String inputFile)
    {
        BufferedReader reader = null;
        int row = 0;

        _theWorld = new Tile[_height][_width];

        try
        {
            reader = new BufferedReader(new FileReader(inputFile));
            String line = null;

            while ((line = reader.readLine()) != null)
            {
                for (int i = 0; i < line.length(); i++)
                {
                    if (TileId.valid(line.charAt(i)))
                        _theWorld[row][i] = new Tile(line.charAt(i));
                    else
                        System.out.println("Invalid world entry: "+line.charAt(i));
                }

                row++;
            }
        }
        catch (Throwable ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            try
            {
                reader.close();
            }
            catch (Throwable ex)
            {
            }
        }
    }

    private Tile[][] _theWorld;
    private int _height;
    private int _width;
}
@@ -1186,24 +1186,1079 @@
 %5D;%0A        %0A
+        for (int i = 0; i %3C _height; i++)%0A        %7B%0A            for (int j = 0; j %3C _width; j++)%0A            %7B%0A                int adjacentBugs = 0;%0A                int emptySpaces = 0;%0A%0A                // ignore range checking and rely on exception!%0A%0A                try%0A                %7B%0A                    if (adjacentBug(i-1, j))%0A                        adjacentBugs++;%0A                    else%0A                        emptySpaces++;%0A%0A                    if (adjacentBug(i+1, j))%0A                        adjacentBugs++;%0A                    else%0A                        emptySpaces++;%0A%0A                    if (adjacentBug(i, j-1))%0A                        adjacentBugs++;%0A                    else%0A                        emptySpaces++;%0A%0A                    if (adjacentBug(i, j+1))%0A                        adjacentBugs++;%0A                    else%0A                        emptySpaces++;%0A                %7D%0A                catch (IndexOutOfBoundsException ex)%0A                %7B%0A                    emptySpaces++;%0A                %7D%0A            %7D%0A        %7D%0A
     %7D%0A%0A    @
@@ -2533,32 +2533,226 @@
 urn str;%0A    %7D%0A%0A
+    private boolean adjacentBug (int i, int j) throws IndexOutOfBoundsException%0A    %7B%0A        if (_theWorld%5Bi%5D%5Bj%5D.isBug())%0A            return true;%0A        else%0A            return false;%0A    %7D%0A%0A
     private void

Update Grid.java