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

home / study / questions and answers / engineering / computer science / how can

ID: 3760120 • Letter: H

Question

home / study / questions and answers / engineering / computer science / how can i change the following program and implement ...

Question

How can I change the following program and Implement a print() method for Percolation that prints 1 for blocked site, 0 for open sites and * for full sites?

public class Visualizeheimadaemi {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
double p = Double.parseDouble(args[1]);
int M = Integer.parseInt(args[2]);

// repeatedly created N-by-N matrices and display them using standard draw
for (int i = 0; i < M; i++) {
boolean[][] open = Percolation.random(N, p);
StdDraw.clear();
StdDraw.setPenColor(StdDraw.BLACK);
Percolation.show(open, false);
StdDraw.setPenColor(StdDraw.GRAY);
boolean[][] full = Percolation.flow(open);
Percolation.show(full, true);
StdDraw.show(1000);
}
}

How can I get the program to print out 1 for blocked, 0 for open and * for full sites? using system.out.print

Explanation / Answer

public class Visualizeheimadaemi {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
double p = Double.parseDouble(args[1]);
int M = Integer.parseInt(args[2]);
// repeatedly created N-by-N matrices and display them using standard draw
for (int i = 0; i < M; i++) {
boolean[][] open = Percolation.random(N, p);
StdDraw.clear();
StdDraw.setPenColor(StdDraw.BLACK);
Percolation.show(open, false);
StdDraw.setPenColor(StdDraw.GRAY);
boolean[][] full = Percolation.flow(open);
Percolation.show(full, true);
StdDraw.show(1000);
}
}