I am writing a class in java of Monte-Carlo algorithm. Here is the written code -
public class MonteCarlo {
int[][] matrix;
public void monteCarlo(List<Node> nodeList) {
matrix = new int[nodeList.size()][nodeList.size()];
initMatrix(nodeList, matrix);
}
private void initMatrix(List<Node> list, int[][] matrix) {
}
}
public class TestMain {
public static void main(String[] args) throws IOException{
GraphGenerator generator = new GraphGenerator();
List<Node> nodeList = generator.graphGenerator(50, 11000, 6000, 40);
MonteCarlo monteCarlo = new MonteCarlo();
monteCarlo.monteCarlo(nodeList);
}
}
In here initMatrix
method i am passing two parameter. But the matrix
array is globally declared. I personally sometime found that is helpful to keep track which method is responsible for what. But is it a bad coding practice to pass a variable parameter even it is declared in globally.
monteCarlo
method is problematic: it modifies a global variable not passed as an argument, which may be puzzling to readers of your code. Better to assign tomatrix
outside the method.monteCarlo
method has been updated. please take a look.