I am making a class called Matrix. Its instance variables should be the number of rows, the number of columns, and the 2D int array representing the matrix (in math). It has methods getDeterminant()that gets its determinant, and it should be able to reproduce with another matrix.
My question is in the constructor, how to initialize it? If it accepts a finished 2D array, so its constructor looks like this:
public class Matrix {
private int[][] matrix;
public Matrix(int[][] matrix) {
this.matrix = matrix;
}
}
or should he create it inside the constructor so that it looks like
public class Matrix {
private int[][] matrix;
public Matrix(int rows, int columns) {
Scanner in = new Scanner(System.in);
}
}
EDIT: Or, should I have a method that initializes it as
public class Matrix {
private int[][] matrix;
public Matrix() {
}
public int[][] initializeMatrix(int rows, int columns) {
}
}
source
share