Skip to content
Snippets Groups Projects
Commit 538d361d authored by POUSSARDIN Malo's avatar POUSSARDIN Malo
Browse files

fin tp6

parent fb1d1cf7
No related branches found
No related tags found
No related merge requests found
Pipeline #40508 failed
......@@ -2,15 +2,14 @@ package matrix;
public class ConstantMatrixInitializer<T> implements MatrixInitializer<T> {
// TODO: add instance variables
private final T value;
public ConstantMatrixInitializer(T constant) {
// TODO
this.value = constant;
}
@Override
public T initialValueAt(Coordinate coordinate) {
// TODO
return null;
return value;
}
}
package matrix;
import java.util.ArrayList;
import java.util.List;
......@@ -23,11 +24,19 @@ 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.initializeWith(initializer); // fills the matrix using initializer
this.initializeWith(initializer);
for (int i = 0; i < height; i++) {
List<T> row = new ArrayList<>(width);
for (int j = 0; j < width; j++) {
row.add(null);
}
matrix.add(row);
}
this.initializeWith(initializer);
}
public ListMatrix(int width, int height, T constant) {
......@@ -35,29 +44,30 @@ 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 i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix.get(i).size(); j++) {
matrix.get(i).set(j, initializer.initialValueAt(Coordinate.of(i,j)));
}
}
}
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;
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