Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA HELP: 2-dimensional arrays Write three methods for the Matrix class that correspond to the three basic operation described below: addition: two matrices must be
JAVA HELP: 2-dimensional arrays Write three methods for the Matrix class that correspond to the three basic operation described below: addition: two matrices must be the same size; add corresponding elements to create a new matrix that holds the sum of the values in the original matrices; scalar multiplication: all elements of a matrix are multiplied by a single number transpose: The transpose of a matrix is a new matrix in which the elements of each row of the original matrix becomes the corresponding column of the new matrix; All three methods should return a Matrix value; since addition requires that the two matrices to be added are equal in size, your addition method should return null if the argument passed to the method isn't the same size as the calling object. /** * Matrix class describes operations on a matrix of integers */ public class Matrix { private int [][] grid; /** * default constructor: creates 3x3 matrix with random values * in the range 0..9 */ public Matrix() { grid = new int[3][3]; for(int x=0; x<3; x++) for(int y=0; y<3; y++) grid[x][y] = (int)(Math.random()*10); } /** * Creates matrix of specified size with random values 0..9 * @param size positive integer that represents the number of rows * and columns in the matrix */ public Matrix(int size) { grid = new int[size][size]; for(int x=0; x
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started