Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2: Class Matrix (11 pts) using java We are asked to design a Class called Matrix to perform some operations elementary matrices with integer-valued

Question 2: Class Matrix (11 pts) using java We are asked to design a Class called Matrix to perform some operations elementary matrices with integer-valued square matrices. The class contains (see UML  Figure 1): Private data: oh nligs, o ncols, o matrix: two-dimensional array of integers representing the matrix. Public constants: o ALONGLINES: integer constant which equals 0. o ACCORDING: integer constant which equals 1.

image text in transcribed

Two builders: - The first initializes a matrix of dimensions nligs by ncols with integers random between 0 and 100 inclusive. - The second constructs a matrix from a two-dimensional array of integers. Public methods: - Accessors for private data: nligs, ncols - A method getValueAt(int i, int j) which returns the value of the element (i,j) of the matrix. - A method setValueAt(int i, int j, int newValue) which modifies the value of the element (i,j) of the matrix. - A method transpose() which performs the transposition of the matrix on which was made the call. - A static method flipLeftRight(Matrix A) which returns a Matrix type object which is the permutation of the matrix A around its vertical center (see execution example below) below). - A static method rotateClockwise(Matrix A) which returns a Matrix type object which is the rotation of the matrix A clockwise (rotation 90 degrees). - A static method concatenate(Matrix A, Matrix B, int direction) which returns a Matrix type object which is the concatenation of matrices A and B as follows: a) If direction=Matrix.ALONGLINES, the concatenation is done in the form [A B] b) If direction=Matrix.ACCORDINGCOLUMNS, the concatenation is done in the form [ AT B ] In a) the result matrix has a number of rows equal to the greatest number of rows between A and B. Missing row elements will be filled with zero in the result matrix.

image text in transcribed

In b) the result matrix has a number of columns equal to the greatest number of columns between A and B. Missing column elements will be filled with zero in matrix results. - A toString() method that replaces (override) the toString method in the Object class and prints the contents of the matrix. An example of a test program of this class is given below, the result can be found on the next page, Figure 2(a). Bonus (+2 points): Modify your program to work with matrices rectangular (not necessarily square); see Figure 2(b);

image text in transcribed

Matrice -nligs: int -ncols: int -matrice[][]: int +SELONLIGNES: int +SELONCOLONNES : int +Matrice(nligs: int, ncols: int) +Matrice(matrice[][]: int) +getnligs(): int +getncols(): int +getValueAt(i: int, j:int): int +setValueAt(i: int, j: int, newValue: int) +transpose() + flipleftRight(A: matrice): Matrice +rotateClockwise(A: matrice): Matrice +concatenate(A: matrice, B: Matrice, direction: int): Matrice +toString(): String

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

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions