Question: percolationstats.java Can anyone help me finish the code? import stdlib.StdOut; import stdlib.StdRandom; import stdlib.StdStats; //percolationStats.java public class PercolationStats { private int m; private double[] x;

percolationstats.java Can anyone help me finish the code? import stdlib.StdOut; import stdlib.StdRandom; import stdlib.StdStats; //percolationStats.java public class PercolationStats { private int m; private double[] x; // Performs m independent experiments on an n x n percolation system. public PercolationStats(int n, int m) { // Returns sample mean of percolation threshold. public double mean() { } // Returns sample standard deviation of percolation threshold. public double stddev() { } // Returns low endpoint of the 95% confidence interval. public double confidenceLow() { } // Returns high endpoint of the 95% confidence interval. public double confidenceHigh() { } // Unit tests the data type. [DO NOT EDIT] public static void main(String[] args) { int n = Integer.parseInt(args[0]); int m = Integer.parseInt(args[1]); PercolationStats stats = new PercolationStats(n, m); StdOut.printf("Percolation threshold for a %d x %d system: ", n, n); StdOut.printf(" Mean = %.3f ", stats.mean()); StdOut.printf(" Standard deviation = %.3f ", stats.stddev()); StdOut.printf(" Confidence interval = [%.3f, %.3f] ", stats.confidenceLow(), stats.confidenceHigh()); } import stdlib.StdOut; import stdlib.StdRandom; import stdlib.StdStats; //percolationStats.java public class PercolationStats { private int m; private double[] x; // Performs m independent experiments on an n x n percolation system. public PercolationStats(int n, int m) { if (n <= 0 || m <= 0) { throw new IllegalArgumentException("Illegal n"); } this.m = m; this.x = new double[m]; for (int i = 0; i < m; i++) { int count = 0; Percolation percolation = new ArrayPercolation(m); while (!percolation.percolates()) { int x, y; do { x = StdRandom.uniform(n) + 1; y = StdRandom.uniform(n) + 1; } while (percolation.isOpen(x,y)); percolation.open(x,y); count++; } x[i] = (double) count / n / n; } } // Returns sample mean of percolation threshold. public double mean() { return StdStats.mean(x); } // Returns sample standard deviation of percolation threshold. public double stddev() { return StdStats.stddev(x); } // Returns low endpoint of the 95% confidence interval. public double confidenceLow() { return StdStats.mean(x) - 1.96 * StdStats.stddev(x) / Math.sqrt(m); } // Returns high endpoint of the 95% confidence interval. public double confidenceHigh() { return StdStats.mean(x) + 1.96 * StdStats.stddev(x) / Math.sqrt(m); } // Unit tests the data type. [DO NOT EDIT] public static void main(String[] args) { int n = Integer.parseInt(args[0]); int m = Integer.parseInt(args[1]); PercolationStats stats = new PercolationStats(n, m); StdOut.printf("Percolation threshold for a %d x %d system: ", n, n); StdOut.printf(" Mean = %.3f ", stats.mean()); StdOut.printf(" Standard deviation = %.3f ", stats.stddev()); StdOut.printf(" Confidence interval = [%.3f, %.3f] ", stats.confidenceLow(), stats.confidenceHigh()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!