From b8cfb478e8dc058728ca306966781ed1101c4668 Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Thu, 3 Feb 2022 22:10:20 +0000 Subject: [PATCH] Added constructor for a filled matrix --- .../java/com/mattrixwv/matrix/IntegerMatrix.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java b/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java index 4ab474f..76ea193 100644 --- a/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java +++ b/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java @@ -120,6 +120,22 @@ public class IntegerMatrix{ public IntegerMatrix(IntegerMatrix matrix){ 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 public int get(int row, int col){