Trying to implements the interface functions. Having some issues.
- For makeEmpty() function seems like i need to transverse the matrix but not sure what that means
- For addition and copy function how should i do it
For the test class i havent write yet. Not very sure how to write java class
public class Matrix implements MatrixInterface{
private int [][] matrixArray;
private int dimension;
public Matrix(int n){
matrixArray = new int[n][n];
dimension = n;
}
@Override
public void makeEmpty(int m) {
//check dimension - conditional statement
if(m > dimension){
m = dimension;
}
//transverse the matrix rows and cols
//loops = 2 loops
for(int i=0; i<=m; i++){
for(int j=0; j<=m; j++){
matrixArray[i][j]=0; // matrix at i row and j col =0
}
}
}
@Override
public boolean storeValue(int i, int j, int value) {
for(int p=0; p<=i; p++){
for(int q=0; q<=j; q++){
matrixArray[p][q] = value;
}
}
return true;
}
@Override
public boolean add(MatrixInterface anotherMatrix) {
for (int i=0; i < dimension; i++){
for (int j=0; j < dimension; j++ ){
}
}
return true;
}
@Override
public boolean copy(MatrixInterface anotherMatrix) {
}
@Override
public String toString() {
String outputStr = "";
for(int i=0; i<dimension; ++i){
for(int j=0; j<dimension; ++i){
outputStr += String.format("%4d", matrixArray[i][j]);
}
outputStr += "\n";
}
return outputStr;
}
}
java interface
is boolean type for add() and copy() correct?
public interface MatrixInterface {
void makeEmpty(int m);
boolean storeValue(int i, int j, int value) ;
boolean add(MatrixInterface anotherMatrix);
boolean copy(MatrixInterface anotherMatrix);
}