Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why is my code not running? Here is the assignment link: http://coursera.cs.princeton.edu/algs4/assignments/percolation.html Here is my code for both Percolation and PercolationStats.java: import java.util.Scanner; import edu.princeton.cs.algs4.WeightedQuickUnionUF;

Why is my code not running?

Here is the assignment link: http://coursera.cs.princeton.edu/algs4/assignments/percolation.html

Here is my code for both Percolation and PercolationStats.java:

import java.util.Scanner; import edu.princeton.cs.algs4.WeightedQuickUnionUF;

public class Percolation { private int n; private int virtualTop; private int virtualBottom; private boolean[][] sites; private WeightedQuickUnionUF weightedQuickUnionUF; public Percolation(int n) { if (n

private int xyToIndex(int row, int col) { return (row - 1) * n + col - 1; } private void validateIndex(int row, int col) { if (row n) throw new IndexOutOfBoundsException("Row must be range of 1 ~ N."); if (col n) throw new IndexOutOfBoundsException("Col must be range of 1 ~ N."); } public void open(int row, int col) { validateIndex(row, col); if (!isOpen(row, col)) { int idx = xyToIndex(row, col); sites[row - 1][col - 1] = true; if (row == 1) weightedQuickUnionUF.union(idx, virtualTop); if (row == n) weightedQuickUnionUF.union(idx, virtualBottom); if (row > 1 && isOpen(row - 1, col)) weightedQuickUnionUF.union(idx, xyToIndex(row - 1, col)); if (row 1 && isOpen(row, col - 1)) weightedQuickUnionUF.union(idx, xyToIndex(row, col - 1)); if (col

__________________________________________________________

import java.util.Scanner;

public class PercolationStats { private int count; private Percolation perc; private int[] percentage;

public PercolationStats(int N, int T) { if (N

}

} public double mean() { return StdStats.mean(percentage); } public double stddev() { return StdStats.stddev(percentage);

} public double confidenceLo() { return mean() - ((1.96 * stddev()) / Math.sqrt(count)); } public double confidenceHi() { return mean() + ((1.96 * stddev()) / Math.sqrt(count));

} public static void main (String [] args) { @ SuppressWarnings ("resource") Scanner keyboard = new Scanner(System.in); System.out.print("Enter int N for N x N grid: "); int N = keyboard.nextInt (); System.out.print("Enter T number of experiments: "); int T = keyboard.nextInt (); PercolationStats stats = new PercolationStats(N, T); System.out.println("% java PercolationStats " + N + " " + T); System.out.println("mean = " + stats.mean()); System.out.println("stddev = " + stats.stddev() + ""); System.out.println("95% confidence interval = " + stats.confidenceLo() + ", " + stats.confidenceHi());

}

}

This is what happens when I try to compile it on Eclipse: image text in transcribed

eclipse-workspace-CSC-3317 Hw04/src/percolationstats.java-Eclipse Eile Edit Source Refactor Navigate Search Project un Window Help Quick Access! . -B D Perc Task List 3-3 olationStats.jawa | D-percolation.java 4 public class Percolationstats Package Explorer X > Assignment 1 CSC-3317 Hwo2 cSC-3317HW04 CSC-3317-HW03 csc3317,HW01.zip-expanded private int count; private Percolation perc; private inti] percentage; > Find a-All, Activate > > public PercolationStats (int N, int T) 12 13 if (

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions