Skip to content
Snippets Groups Projects
Commit 7f865e4e authored by SAHIN Melis damla's avatar SAHIN Melis damla
Browse files

Compléter la classe ListMatrix

parent bd8c7028
No related branches found
No related tags found
No related merge requests found
Pipeline #38341 failed
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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment