Added constructor for a filled matrix

This commit is contained in:
2022-02-03 22:10:20 +00:00
parent 536c299bea
commit b8cfb478e8

View File

@@ -120,6 +120,22 @@ public class IntegerMatrix{
public IntegerMatrix(IntegerMatrix matrix){ public IntegerMatrix(IntegerMatrix matrix){
setGrid(matrix.grid); setGrid(matrix.grid);
} }
public IntegerMatrix(int rows, int cols, int fill){
if(rows <= 0){
throw new InvalidGeometryException("A filled matrix must have at least 1 row");
}
else if(cols <= 0){
throw new InvalidGeometryException("A filled matrix must have at least 1 column");
}
else{
grid = new int[rows][cols];
for(int row = 0;row < rows;++row){
for(int col = 0;col < cols;++col){
grid[row][col] = fill;
}
}
}
}
//Gets //Gets
public int get(int row, int col){ public int get(int row, int col){