I am suppose to write a method to check if the array is equal an object... \" Re
ID: 3743536 • Letter: I
Question
I am suppose to write a method to check if the array is equal an object...
" Returns true if this matrix matches another matrix.", here's some of my code
int[][] data2 = {{1,2,3},{4,5,6},{7,8,9}}
int[][] data3 = {{1,4,7},{2,5,8},{3,6,9}}
Matrix m1 = new MyMatrix(data2);
Matrix m2 = new MyMatrix(data3);
.........................................................
System.out.println("m2==null: " + m2.equals(null)); //FALSE
System.out.println("m2=="MATRIX" : " + m2.equals("MATRIX")); FALSE
System.out.println("m2==m2 : " + m2.equals(m2)); //TURE
..........................................................
public boolean equals(Object other){ }
.............................................................
Explanation / Answer
Below is your code for equals method
public boolean equals(Object other)
{
if (other == this)
{
return true;
} else
return false;
}
public String toString()
{
StringBuffer sb = new StringBuffer("[");
for (int i = 0; i < rowvalue; i++)
{
sb.append("[");
for (int j = 0; j < columnvalue; j++)
sb.append(" " + newMatrix[i][j] + " ");
sb.append("]");
}
return sb + "]";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.