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

Needs to be written in java.. -I need some help getting setup in the right direc

ID: 3662699 • Letter: N

Question

Needs to be written in java..
-I need some help getting setup in the right direction.. you dont need to program this whole thing.. I dont even know how to disect this assignment nor the questions to ask.. if you could take some time to explain what i need to do , and maybe setup some of the methods which can steer me in the right direction that would be great ! thanks so much

Programming Assignment 1: Percolation Write a program to estimate the value of the percolation threshold via Monte Carlo simulation. 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-N grid of sites. Each site is either open or blocked. A full 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.) percolates does not percolate blocked site full empty open site site open site connected to top no open site connected to top The problem. In a famous scientific problem, researchers are interested in the following question: if sites are independently 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) 1 percolation probability percolation probability 0.5931 0 0.5931 site vacancy probability p site vacancy probability p When N is sufficiently large, there is a threshold value p such that when p p*, a random N-by-N grid almost always percolates. No mathematical solution

Explanation / Answer

**********Here is the code for your program****************

Percolation.java

public class Percolation
{
private int[][] siteStatus;
private int count;
private WeightedQuickUnionUF quickunion;
private int N;
public Percolation(int N)
{
this.N = N;
siteStatus = new int[N][N];
quickunion = new WeightedQuickUnionUF((N*N)+2);
count = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
//initialise site status as blocked
siteStatus[i][j] = 1;
//initialise site ids
count++;
if (i == 0)
{
quickunion.union(count, 0);
}
else if (i == N-1)
{
quickunion.union(count, (N*N)+1);
}
}
}
}
public void open(int i, int j)
{
int x, y;
x = i-1;
y = j-1;
siteStatus[x][y] = 0;
for (int a = x-1; a <= x+1; a += 2)
{
if (a >= 0 && a < N && y >= 0 && y < N)
{
if (isOpen(a+1, y+1))
{
quickunion.union((a*N)+(y+1), (x*N)+j);
}
}
}
for (int b = y-1; b <= y+1; b += 2)
{
if (x >= 0 && x < N && b >= 0 && b < N)
{
if (isOpen(x+1, b+1))
{
quickunion.union((x*N)+(b+1), (x*N)+j);
}
}
}
}
public boolean isOpen(int i, int j)
{
if (i > 0 && i <= N && j > 0 && j <= N)
{
return siteStatus[i-1][j-1] == 0;
} else {
throw new IndexOutOfBoundsException("Values are out of range");
}
}
public boolean isFull(int i, int j)
{
if (i > 0 && i <= N && j > 0 && j <= N) {
if (quickunion.connected(((i-1)*N) + j, 0))
{
return siteStatus[i-1][j-1] == 0;
}
else
{
return false;
}
}
else
{
throw new IndexOutOfBoundsException("Values are out of range");
}
}
public boolean percolates()
{
return quickunion.connected(0, (N*N)+1);
}
}


PercolationStats.java

public class PercolationStats
{
private Percolation percolation;
private double[] threshold;
private double T;
private int openSites;
public PercolationStats(int T, int N)
{
if (N <= 0 || T <= 0)
{
throw new IllegalArgumentException("Value is out of range");
}
threshold = new double[T];
int randx, randy;
this.T = T;
for (int i = 0; i < T; i++)
{
percolation = new Percolation(N);
randx = StdRandom.uniform(1, N+1);
randy = StdRandom.uniform(1, N+1);
percolation.open(randx, randy);
openSites = 1;
while (!percolation.percolates())
{
randx = StdRandom.uniform(1, N+1);
randy = StdRandom.uniform(1, N+1);
if (!percolation.isOpen(randx, randy))
{
percolation.open(randx, randy);
openSites++;
}
}
threshold[i] = ((double) openSites)/(N*N);
}
}
public double mean()
{
return StdStats.mean(threshold);
}
public double stddev()
{
return StdStats.stddev(threshold);
}
public double confidenceLo()
{
return mean() - (1.96*stddev())/Math.sqrt(T);
}
public double confidenceHi()
{
return mean() + (1.96*stddev())/Math.sqrt(T);
}
public static void main(String[] args)
{
int T, N;
T = Integer.parseInt(args[0]);
N = Integer.parseInt(args[1]);
PercolationStats percolationStats = new PercolationStats(T, N);
//Instead of StdOut.println() function, you can use your own output format
StdOut.println("%Java PercolationStats " + T + " " + N);
StdOut.println("Mean "+percolationStats.mean());
StdOut.println("stddev " + percolationStats.stddev());
StdOut.println("95% confidence interval = "+ percolationStats.confidenceLo()+ ", " + percolationStats.confidenceHi());
}
}

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