1. Create a class named SquareMatrix with two instance variables: an integer named size that contains the size of the ma
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
1. Create a class named SquareMatrix with two instance variables: an integer named size that contains the size of the ma
1. Create a class named SquareMatrix with two instancevariables: an integer namedsize that contains the size of the matrix, and a two dimensionalarray namedelements that contains the elements of the matrix. Write thefollowing methods:• Constructor: takes an integer parameter for size, checks that itis a valuebetween 1 and 5 inclusive, and creates the two dimensional arrayelementswith size rows and size columns and initializes it with randomvaluesbetween 0 and 9 inclusive. If the size parameter is out of range,size shouldbe initialized to 5• String toString(): returns a string containing the elements ofthe matrixproperly formatted, with each row in a new line• int getSize(): returns the size of the matrix• void setElement(int row, int col, int value): checks if row andcol define avalid location and sets the corresponding element to value• int getElement(row, col): checks if row and col define a validlocation andreturn the value of the corresponding element; if the location isinvalid,return -1• Draw a UML diagram for your program. Scan it using a scanner apponyour phone, or take a clear picture. Save as pdf.2. Write an application called Driver calls each method of theSquareMatrix class atleast once.