Question
public class Matrix { // Declare a two dimensional array of doubles as field data /** * Constructor for objects of class Matrix */ public
public class Matrix { // Declare a two dimensional array of doubles as field data
/** * Constructor for objects of class Matrix */ public Matrix(double [][] matrix) { // Allocate storage for field data variable
// Copy values in parameter matrix to field data variable. // This is to be a deep copy, meaning all the values of matrix are // assigned to the field data variable.
}
/** * Return the element of the matrix stored in the indicated row and column * * @param row row of the element to be returned * @param col column of the element to be returned. * @return the element stored in the indicated row and column. */ public double getElement(int row, int col) { return 0; }
/** * Determine if the matrix is square in size. * A matrix is square if the number of rows equals the number of columns * * @return true if this matrix is square */ public boolean isSquare() { return true; }
/** * Compute sum of specified column * * @param col the column whose sum is computed * @return average of matrix elements */ public double columnSum(int col) { return 0.0; }
/** * Compute the average of all elements in the Matrix * * @return average of matrix elements */ public double average() { return 0.0; }
/** * If matrix is square, then compute sum of elements * on the major diagonal. If matrix isn't square, then return zero. * The major diagonal goes from the top left corner to the bottom right * corner. * * @return sum of the elements on the major diagonal */ public double sumDiagonal() { return 0.0; }
/** * Scalar Addition. Add the value x to every element of the matrix. * * @param x value to be added to the matrix * @return the matrix with x added to every element. * Notice that a two dimensional array is returned. */ public double [][] scalarAddition(double x) { // Hint: Create 2 dimensional array to be used as the return value return null; }
/** * Extra Credit. * Matrix Multiplciation. Multiply this matrix by x * * @param x this matrix is multplied by x * @return the product of this matrix times x. * Notice that a two dimensional array is returned. */ public double [][] multiply(double[][] x) { return null; }
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