Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here are requirements and deliverables required from this question I need the he

ID: 3587476 • Letter: H

Question

Here are requirements and deliverables required from this question I need the help of some java expert in doing this ASAP:

Deliverables.
1) Submit only Percolation.java (using the weighted quick-union algorithm as implemented in the WeightedQuickUnionUF class) and PercolationStats.java.stdlib.jar is available at
http://introcs.cs.princeton.edu/java/stdlib/ and WeightedQuickUnionUF.java is available at http://algs4.cs.princeton.edu/code/. On this assignment, the only library functions you may call are those in java.lang,stdlib.jar and WeightedQuickUnionUF.java.
2) Submit a readme.txt file and answer question.

Programming Assignment : Percolation Case Study Assn: 4a Write a program to estimate the value of the percolation threshold via Monte Carlo simulation Install a Java programming environment. Install a Java programming environment on y our computer by following these step-by-step instructions for y our operating system [ Mac OS X Windows Linux. After following these instructions you will have stdlibiar and algs4.jar in y our Java classpath: the former contains libraries for reading data from standard input, writing data to standard output, drawing results to standard drav, generating random numbers, computing statistics, and timing programs; the latter contains all of the algorithms in the textbook Percolation. Given a composite systems comprised of randomly distributed insulating and metallic materials: what fraction of the materials need to be metallic so that the composite system is an electrical conductor? Given a porous landscape with water on the surface (or oil below), under what conditions will the water be able to drain through to the bottom (or the oil to gush through to the surface)? Scientists have defined an abstract process known as percolation to model such situations The model. We model a percolation system using an N-by-Ngrid of sites. Each site is either open or blocked. Afull site is an open site that can be connected to an open site in the top row via a chain of neighboring (left, right, up, down) open sites. We say the system percolates if there is a full site in the bottom row. In other words, a system percolates if we fill all open sites connected to the top row and that process fills some open site on the bottom row. (For the insulating/metallic materials example, the open sites correspond to metallic materials, so that a system that percolates has a metallic path from top to bottom, with full sites conducting. For the porous substance example, the open sites correspond to empty space through which water might flow, so that a system that percolates lets water fill open sites, flowing from top to bottom.) The problem. In a famous scientific problem, researchers are interested in the following question if sites are independntly set to be open with probability p (and therefore blocked with probability 1 p), what is the probability that the system percolates? When p equals 0, the system does not percolate; when p equals 1, the system percolates. The plots below show the site vacancy probability p versus the percolation probability for 20-by-20 random grid (left) and 100-by-100 random grid (right)

Explanation / Answer

PercolationStats.java

public class PercolationStats {

    private double[] mX;
    private double   mMean, mStdDev;

    // perform T independent computational experiments on an N-by-N grid
    public PercolationStats(final int n, final int t) {
        if (n <= 0 || t <= 0) {
            throw new java.lang.IllegalArgumentException();
        }

        mX = new double[t];

        for (int i = 0; i < t; i++) {
            Percolation p = new Percolation(n);
            int openSites = 0;

            while (!p.percolates()) {
                int row, col;

                do {
                    row = StdRandom.uniform(1, n + 1);
                    col = StdRandom.uniform(1, n + 1);
                } while (p.isOpen(row, col));

                p.open(row, col);
                openSites++;
            }

            mX[i] = ((double) openSites) / (n * n);
        }

        mMean = StdStats.mean(mX);
        mStdDev = StdStats.stddev(mX);
    }

    // sample mean of percolation threshold
    public final double mean() {
        return mMean;
    }

    // sample standard deviation of percolation threshold
    public final double stddev() {
        return mStdDev;
    }

    // test client, described below
    public static void main(final String[] args) {
        // TODO Auto-generated method stub
        if (args.length < 2) {
            throw new java.lang.IllegalArgumentException();
        }

        int n = Integer.parseInt(args[0]);
        int t = Integer.parseInt(args[1]);

        PercolationStats ps = new PercolationStats(n, t);

        double mean = ps.mean();
        double stddev = ps.stddev();
        System.out.printf("mean                    = %f ", mean);
        System.out.printf("stddev                  = %f ", stddev);

        final double intervalConstant = 1.96;
        double interval = (stddev * intervalConstant) / Math.sqrt(t);
        System.out.printf("95%% confidence interval = %f, %f ", mean
                - interval, mean + interval);
    }

}

Percolation.java

public class Percolation {

    private WeightedQuickUnionUF mUf, mIsFullUf;
    private boolean[][]          mSites;
    private int                  mN;
    private boolean              mPercolates;

    public Percolation(final int n) {
        mN = n;

        // N-by-N grid with 2 virtual sites
        mUf = new WeightedQuickUnionUF(mN * mN + 2);
        mIsFullUf = new WeightedQuickUnionUF(mN * mN + 1);

        mSites = new boolean[mN][mN];

        for (int i = 0; i < mN; i++) {
            for (int j = 0; j < mN; j++) {
                mSites[i][j] = false;
            }
        }

        mPercolates = false;
    }

    public final void open(final int i, final int j) {
        if (i < 1 || j < 1 || i > mN || j > mN) {
            throw new java.lang.IndexOutOfBoundsException();
        }

        if ((i + 1) <= mN && isOpen(i + 1, j)) {
            mUf.union(site(i, j), site(i + 1, j));
            mIsFullUf.union(site(i, j), site(i + 1, j));
        }

        if ((i - 1) >= 1 && isOpen(i - 1, j)) {
            mUf.union(site(i, j), site(i - 1, j));
            mIsFullUf.union(site(i, j), site(i - 1, j));
        }

        if (j > 1 && isOpen(i, j - 1)) {
            mUf.union(site(i, j), site(i, j - 1));
            mIsFullUf.union(site(i, j), site(i, j - 1));
        }

        if (j < mN && isOpen(i, j + 1)) {
            mUf.union(site(i, j), site(i, j + 1));
            mIsFullUf.union(site(i, j), site(i, j + 1));
        }

        // Connect to top virtual site
        if (i == 1) {
            mUf.union(0, site(i, j));
            mIsFullUf.union(0, site(i, j));
        }

        // Connect to bottom virtual site
        if (i == mN) {
            mUf.union(site(i, j), mN * mN + 1);
        }

        mSites[i - 1][j - 1] = true;
    }

    public final boolean isOpen(final int i, final int j) {
        if (i < 1 || j < 1 || i > mN || j > mN) {
            throw new java.lang.IndexOutOfBoundsException();
        }

        return mSites[i - 1][j - 1];
    }

    public final boolean isFull(final int i, final int j) {
        if (i < 1 || j < 1 || i > mN || j > mN) {
            throw new java.lang.IndexOutOfBoundsException();
        }

        return mIsFullUf.connected(0, site(i, j));
    }

    public final boolean percolates() {
        if (!mPercolates) {
            mPercolates = mUf.connected(0, mN * mN + 1);
        }

        return mPercolates;
    }

    private int site(final int i, final int j) {
        return (i - 1) * mN + j;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote