From 7f865e4ed75bb30cb3c39ca589784b85e951080a Mon Sep 17 00:00:00 2001 From: s23026062 <melis-damla.sahin@etu.univ-amu.fr> Date: Fri, 8 Nov 2024 16:12:51 +0100 Subject: [PATCH] =?UTF-8?q?Compl=C3=A9ter=20la=20classe=20ListMatrix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/matrix/ListMatrix.java | 30 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/matrix/ListMatrix.java b/src/main/java/matrix/ListMatrix.java index a3a4e7d..0e9bf48 100644 --- a/src/main/java/matrix/ListMatrix.java +++ b/src/main/java/matrix/ListMatrix.java @@ -1,5 +1,6 @@ package matrix; +import java.util.ArrayList; import java.util.List; @@ -23,10 +24,9 @@ public class ListMatrix<T> implements Matrix<T> { * @param initializer A matrix initializer to set values in the {@link ListMatrix}. */ public ListMatrix(int width, int height, MatrixInitializer<T> initializer) { - // TODO - this.width = 0; - this.height = 0; - this.matrix = null; + this.width = width; + this.height = height; + this.matrix = new ArrayList<>(width); this.initializeWith(initializer); // fills the matrix using initializer } @@ -35,29 +35,33 @@ public class ListMatrix<T> implements Matrix<T> { } private void initializeWith(MatrixInitializer<T> initializer) { - // TODO initialize each cell of the matrix, with a value determined by initializer + for (int x=0; x<width; x++) { + List<T> column = new ArrayList<>(height); + for (int y=0; y<height; y++) { + column.add(initializer.initialValueAt(new Coordinate(x, y))); + } + matrix.add(column); + } + } public int width() { - // TODO - return 0; + return width; } public int height() { - // TODO - return 0; + return height; } @Override - public T get(int x, int y) { - // TODO - return null; + public T get(int x, int y) { // une liste de listes + return matrix.get(x).get(y); } @Override public void set(int x, int y, T newValue) { - // TODO + matrix.get(x).set(y,newValue); } } -- GitLab