(Solved) : Java Matrix Emphasis Abstract Data Types Mutability Answer Question Please Easy Read Manne Q17891628 . . .

JAVA Matrix with emphasis on Abstract DataTypes and Mutability

If you answer this question, please do so in an EASY-TO-READmanner, ie DO NOT WRITE YOUR ANSWER ON PAPER THEN TAKE APICTURE OF IT! Type it out and copy/paste, or usescreenshots from your own java IDE. Keepin mind I’m on NetBeans 8.0.2. Also be sure to keep thesame nomenclature for the classes/methods andfollow the documentation that tells you how each methodshould work. I’ve seperated the question and the twoclasses below with lines of “——–” to make it easier toread.

If you do not follow these instructions then I will voteyou down for wasting my question.

—————————————————————

—————————————————————

For this assignment, you will implement the provided matrixinterface (Matrix.java). This interface defines not only whichmethods you must implement, but gives documentation thatdescribes how they should work. Already provided for youis a base to modify (base.java). The base contains a currentlyempty matrix class as well as some simple testing code. In orderfor it to be a reliable type, we will implement it as animmutable type. Creating this ADT (abstract data type)will involve creating 9 methods:

• MyMatrix(double[][] matrix) – a constructor. [4 points]

• public double getElement(int y, int x) – see interface. [2points]

• public int getRows() – see interface. [2 points]

• public int getColumns() – see interface. [2 points]

• public MyMatrix scale(double scalar) – see interface. [5points]

• public MyMatrix plus(Matrix other) – see interface. [5points]

• public MyMatrix minus(Matrix other) – see interface. [5points]

• boolean equals(Object other) – see interface. [5 points]Recall that methods have two parts: a signature (i.e. its name,type, and what parameters it takes), a body (the actual code thatimplements the method’s functionality).

• String toString() – see interface. [5 points].

Be aware that some of the methods throw exceptions – this shouldbe implemented.

—————————————————————

/**
* An implementation of the Matrix ADT (abstract data type).Provides four basic operations over an
* immutable type.
*/
public class base implements Matrix {

//TODO: implement interface.

/**
* Entry point for matrix testing.
* @param args the command linearguments
*/
public static void main(String[] args) {

int[][] data1 = newint[0][0];
int[][] data2 = {{1, 2,3}, {4, 5, 6}, {7, 8, 9}};
int[][] data3 = {{1, 4,7}, {2, 5, 8}, {3, 6, 9}};

Matrix m1 = newser222_unit12b_hw02_base(data1);
Matrix m2 = newser222_unit12b_hw02_base(data2);
Matrix m3 = newser222_unit12b_hw02_base(data3);

System.out.println(“m1–> Rows: ” + m1.getRows() + ” Columns: ” +m1.getColumns());
System.out.println(“m2–> Rows: ” + m2.getRows() + ” Columns: ” +m2.getColumns());
System.out.println(“m3–> Rows: ” + m3.getRows() + ” Columns: ” +m3.getColumns());

//check for referenceissues
System.out.println(“m2–>n” + m2);
data2[1][1] = 101;
System.out.println(“m2–>n” + m2);

//test equals
System.out.println(“m2==null: ” +m2.equals(null));            //false
System.out.println(“m3==”MATRIX”: ” +m2.equals(“MATRIX”));   //false
System.out.println(“m2==m1: ” +m2.equals(m1));                //false
System.out.println(“m2==m2: ” +m2.equals(m2));                //true
System.out.println(“m2==m3: ” +m2.equals(m3));                //false

//test operations(valid)
System.out.println(“2 *m2:n” + m2.scale(2));
System.out.println(“m2 +m3:n” + m2.plus(m3));
System.out.println(“m2 -m3:n” + m2.minus(m3));

//test operations(invalid)
//System.out.println(“m1+ m2” + m1.plus(m2));
//System.out.println(“m1- m2” + m1.minus(m2));
}
}

—————————————————————

/**
* A simple matrix ADT (abstract data type).
*/
public interface Matrix {

/**
* Returns the element at particular pointin the matrix.
* @param y y position
* @param x x position
* @return element
*/
public int getElement(int y, int x);

/**
* Returns the number of rows in thematrix.
* @return rows
*/
public int getRows();

/**
* Returns the number of columns in thematrix.
* @return columns
*/
public int getColumns();

/**
* Returns this matrix scaled by a factor.That is, computes kA where k is a
* constant and A is a matrix (thisobject).
*
* @param scalar scalar
* @return matrix
*/
public Matrix scale(int scalar);

/**
* Returns this matrix added with anothermatrix. That is, computes A+B
* where A and B are matrices (this object,and another respectively).
* @param other addend
* @return matrix
* @throws RuntimeException if matrices donot have matching dimensions.
*/
public Matrix plus(Matrix other);

/**
* Returns this matrix subtracted byanother matrix. That is, computes A-B
* where A and B are matrices (this object,and another respectively).
* @param other subtrahend
* @return matrix
* @throws RuntimeException if matrices donot have matching dimensions.
*/
public Matrix minus(Matrix other);

/**
* Returns true if this matrix matchesanother matrix.
* @param other another matrix
* @return equality
*/
@Override
public boolean equals(Object other);

/**
* Returns a string representation of thismatrix. A new line character will
* separate each row, while a space willseparate each column.
* @return string representation
*/
@Override
public String toString();
}

Expert Answer


/Matrix.java

public interface Matrix
{

public double getElement(int y, int x); . . .