/**
 * Percolation.java - class for an N-by-N grid that can test for percolation
 * Joe Ryan, 23 July 2014
 * Creates an N-by-N grid
 * open(row, column) allows opening of elements
 * isOpen(row, column) tests the state of element at (row, column)
 *    and returns true if open
 * isFull(row, column) tests the ??
 * percolates() tests system for a path from the bottom row all the way through
 * to the top row and returns true if a valid path exists from row 1 to row N
 */

public class Percolation {
    private WeightedQuickUnionUF[] grid;
    private boolean[] state;
    private int size;
    
    public Percolation(int N) {  /**
     * create N by N grid with all sites blocked
     * the integer N must be > 0 and determines the size of the grid
     * @param N specifies the size of the square grid to create
     */
        grid = new WeightedQuickUnionUF [N*N];
        state = new boolean [N*N];
        size = N;
    }
    
    public void open(int i, int j) {  /**
     * opens the site (row i, column j) if it not already open
     */
        if (!isOpen(i, j)) { state[i*size+j] = true; }
    }
    
    public boolean isOpen(int i, int j) {  /**
     * is site (row i, column j) is currently open?
     * returns true if site is open and false otherwise
     * @param i row for site being checked
     * @param j column for site being checked
     */
       
        return state[i*size+j];
       
    }
    public boolean isFull(int i, int j) {  /**
     * is site (row i, column j) full?
     * returns true if site is full?? and false otherwise
     * @param i row for site being checked
     * @param j column for site being checked
     */ 
        // TODO
        return true; // TODO fix return stub
    }
    public boolean percolates() {  /**
     * does the system percolate?
     * returns true if a path exists from row 1 to row N between open sites
     */
        // TODO
        return true; // TODO fix return stub
    }

    public static void main(String[] args) {
        int N = Integer.parseInt(args[0]);
        Percolation percolator = new Percolation(N);
        percolator.open(1, 1);
        percolator.open(0, 0);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                StdOut.println(percolator.isOpen(i, j));
            }
        }
    }
}
    
    
                         

@@ -107,78 +107,533 @@
 %0A * 
-Creates an N-by-N grid%0A * open(row, column) allows opening of elements
+Dependencies: stdlib.jar and algs4.jar (libraries provided by Algorithms class%0A * Command Line usage: java Percolation %3Csize of grid N%3E%0A * Constructor creates an N-by-N grid using a single WeightedQuickUnionUF object%0A *    initialized with all elements closed%0A * main() reads two entries from stdin while available, opens element at i,j%0A *    and when no more entries are available prints //TODO output %0A * .open(row, column) allows opening of a single element, any surrounding element%0A *    which is opened is then connected
 %0A * 
@@ -671,16 +671,19 @@
 tate of 
+an 
 element 
@@ -725,16 +725,22 @@
 true if 
+it is 
 open%0A * 
@@ -769,18 +769,114 @@
 sts the 
-??
+element to see if it can connect to the top%0A *    pseudo row indicating any element in the top row
 %0A * perc
@@ -950,16 +950,19 @@
 rough%0A *
+   
  to the 
@@ -1377,32 +1377,190 @@
  create%0A     */%0A
+        if (N %3C 0) %7B%0A            throw new IndexOutOfBoundsException(%0A                %22Initial size of system must be equal to or greater than 1%22);%0A        %7D%0A
         grid = n
@@ -1759,32 +1759,254 @@
 dy open%0A     */%0A
+        if (i %3C= 0 %7C%7C i %3E size) throw %0A            new IndexOutOfBoundsException(%22row index i out of bounds%22);%0A        if (j %3C= 0 %7C%7C j %3E size) throw %0A            new IndexOutOfBoundsException(%22row index j out of bounds%22);%0A
         if (!isO
@@ -2303,24 +2303,245 @@
 ked%0A     */%0A
+        if (i %3C= 0 %7C%7C i %3E size) throw %0A            new IndexOutOfBoundsException(%22row index i out of bounds%22);%0A        if (j %3C= 0 %7C%7C j %3E size) throw %0A            new IndexOutOfBoundsException(%22row index j out of bounds%22);
        %0A    
@@ -3492,40 +3492,4 @@
 %7D%0A%7D%0A
-    %0A    %0A                         %0A

add code raising exceptions for index out of bounds