Skip to content

Abwas submitting percolation assignment#2

Open
Abwas wants to merge 2 commits intosweskills:masterfrom
Abwas:master
Open

Abwas submitting percolation assignment#2
Abwas wants to merge 2 commits intosweskills:masterfrom
Abwas:master

Conversation

@Abwas
Copy link
Copy Markdown

@Abwas Abwas commented Jun 20, 2017

No description provided.

Copy link
Copy Markdown

@erictoguem erictoguem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good code, but how you name your variables, properly formating your code, or even using the proper javadoc style comment could improve it.

Please do address my comments...

Comment thread Percolation.java
{
checkBounds(a, b);
int x = b;
int y = a;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need these variables. Why don't you just name method parameters a and b to x and y?

Comment thread Percolation.java
if (b > gridLength || b < 1)
{
throw new IndexOutOfBoundsException("column index b out of bounds");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code could be better formatted.

Comment thread Percolation.java
isOpen[virtualBottomIndex] = true; /// open virtual bottom site

percolation = new WeightedQuickUnionUF(arraySize);
fullness = new WeightedQuickUnionUF(arraySize);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fullness doesn't contain bottom virtual site, then could be represented with arraySiye -1 elements.

Comment thread Percolation.java
for (int b = 1; b <= n; b++)
{
/// connect all top row sites to virtual top site
int a = 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this variable.

Comment thread Percolation.java
int indexToLeft = siteIndex(a, b - 1);
percolation.union(siteIndex, indexToLeft);
fullness.union(siteIndex, indexToLeft);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're repeating this pattern 4 times. You could instead create a "private void connect(int siteIndex, int row, int col)" method where you could first check row and column are valids and that the cell is open, before creating the connection...

Comment thread Percolation.java
public boolean isFull(int a, int b)
{
int siteIndex = siteIndex(a, b);
//return (percolation.connected(virtualTopIndex,siteIndex) && isOpen[siteIndex]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you remove this comment, it's not needed at all...

Comment thread Percolation.java
}
else {
return isOpen[siteIndex(1,1)];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have used the ternary operator here instead of the if else...

Comment thread PercolationStats.java
private double[] thresholdResults;

private int T;
// perform T independent computational experiments on an n-by-n grid
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a well formatted javadoc comment and please could you place it closer to PercolationStats

Comment thread Percolation.java
// converts between two dimensional coordinate system and site array index.
// throws exceptions on invalid bounds. valid indices are 1 : n^2
// a is the row; b is the column
private int siteIndex(int a, int b)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming your variables row and column instead of a and b will make your code much more readable. Please could you update this code to use row and column instead of a and b?

Comment thread PercolationStats.java
// holds each experiment's percolation threshold result
private double[] thresholdResults;

private int T;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non final static fields in java shouldn't be capitabilized. Please could you call this one trial instead?

Comment thread Percolation.java
public void open(int row, int col) // open site (row, col) if it is not open already
public boolean isOpen(int row, int col) // is site (row, col) open?
public boolean isFull(int row, int col) // is site (row, col) full?
public int numberOfOpenSites() // number of open sites
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't implement this one... Please could you implement it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants