/******************************************************************************
  *  Compilation: javac-alg4 PercolationStats.java
  *  Execution: java PercolationStats
  * 
  *  Percolation Monte Carlo experiment
  *  Author: Ketong Wang
  */

public class PercolationStats {
    // Some private names to hold data
    private double[] thresholds;
    
    /**
     * Initializes the percolation
     */
    public PercolationStats (int N, int T) { //N dimension, T repeating times
        thresholds = new double[T];
        for (int i = 0; i < T; i++) { // run T experiments
            Percolation percolationItem = new Percolation(N);
            StdOut.println(percolationItem.percolates());
            while (!percolationItem.percolates()) {
                int row = new StdRand.uniform(1, N + 1);
                int col = new StdRand.uniform(1, N + 1);
            }
        }
    }
    
    /**
     * Sample mean of percolation threshold
     */
//    public double mean() {}
    
    /**
     * Sample standard deviation of percolation threshold
     */
//    public double stddev() {}
    
    /**
     * returns lower bound of the 95% confidence interval
     */
//    public double confidenceLo() {}
    
    /**
     * returns upper bound of the 95% confidence interval
     */
//    public double confidenceHi() {}
    
    /**
     * test client, described below
     */
    public static void main(String[] args) {
        StdOut.print("Enter the grid dimension N: ");
        int N = StdIn.readInt();
        StdOut.print("Enter the repeating times of experiments T: ");
        int T = StdIn.readInt();
        
        PercolationStats pStats = new PercolationStats(3, 100);
    }
    
    
    
    
}
@@ -342,21 +342,42 @@
 sholds;%0A
+    private int dim;%0A
     %0A
-
     /**%0A
@@ -463,19 +463,39 @@
 int T) %7B
+                   
  //
+ 
 N dimens
@@ -552,17 +552,91 @@
 uble%5BT%5D;
-%0A
+                             // Save steps to percolate%0A        dim = N;%0A//
         
@@ -664,16 +664,42 @@
 ; i++) %7B
+                          
  // run 
@@ -712,16 +712,18 @@
 riments%0A
+//
         
@@ -776,16 +776,18 @@
 ion(N);%0A
+//
         
@@ -836,16 +836,18 @@
 tes());%0A
+//
         
@@ -886,24 +886,26 @@
 olates()) %7B%0A
+//
             
@@ -917,28 +917,24 @@
 nt row =
- new
  StdRand
 .uniform
@@ -917,32 +917,34 @@
 nt row = StdRand
+om
 .uniform(1, N + 
@@ -939,32 +939,34 @@
 form(1, N + 1);%0A
+//
                 
@@ -978,20 +978,16 @@
 ol =
- new
  StdRand
 .uni
@@ -982,16 +982,18 @@
  StdRand
+om
 .uniform
@@ -1004,16 +1004,18 @@
 N + 1);%0A
+//
         
@@ -1016,24 +1016,26 @@
           %7D%0A
+//
         %7D%0A  
@@ -1475,32 +1475,349 @@
 nceHi() %7B%7D%0A    %0A
+    %0A    /**%0A     * Some private methods. index2Coord(). public first then private%0A     */%0A    private int%5B%5D index2Coord(int index) %7B         // indice are from 0 to dim * dim - 1%0A        int%5B%5D coord = new int%5B2%5D;%0A        coord%5B0%5D = index / dim + 1;%0A        coord%5B1%5D = index %25 3 + 1;%0A        return coord;%0A    %7D%0A    %0A
     /**%0A     * t
@@ -2091,24 +2091,37 @@
 ();%0A        
+             
 %0A        Per
@@ -2168,14 +2168,194 @@
 ats(
-3, 100
+N, T);%0A//        int%5B%5D coord = pStats.index2Coord(7);%0A//        for (int i = 0;  i %3C coord.length; i++) %7B%0A//            StdOut.println(coord%5Bi%5D);%0A//        %7D%0A//        StdOut.println(5%253
 );%0A 

add private method index2Coord(). test