Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am suppose to write a method to check if the array is equal an object... Returns true if this matrix matches another matrix.,

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){ }

.............................................................

public class ser222_01_02_hw02_base implements Matrix { //TODO: implement interface. /** * Entry point for matrix testing. * @param args the command line arguments */ public static void main(String[] args) { int[][] data1 = new int[0][0]; int[][] data2 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int[][] data3 = {{1, 4, 7}, {2, 5, 8}, {3, 6, 9}}; int[][] data4 = {{1, 4, 7}, {2, 5, 8}, {3, 6, 9}}; Matrix m1 = new ser222_01_02_hw02_base(data1); Matrix m2 = new ser222_01_02_hw02_base(data2); Matrix m3 = new ser222_01_02_hw02_base(data3); Matrix m4 = new ser222_01_02_hw02_base(data4); 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 reference issues System.out.println("m2 --> " + m2); data2[1][1] = 101; System.out.println("m2 --> " + 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 System.out.println("m3==m4: " + m3.equals(m4)); //true //test operations (valid) System.out.println("2 * m2: " + m2.scale(2)); System.out.println("m2 + m3: " + m2.plus(m3)); System.out.println("m2 - m3: " + m2.minus(m3)); //not tested... multiply(). you know what to do. //test operations (invalid) //System.out.println("m1 + m2" + m1.plus(m2)); //System.out.println("m1 - m2" + m1.minus(m2)); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

Let f(x) = x - 3 / x + 1. Show that f(f(f(x))) = x, provided x 1.

Answered: 1 week ago