Create a java class named SquareMatrix with two instance variables: an integer named size that contains the size of the matrix, and a two dimensional array named elements that contains the elements of the matrix.
1. Create a java class named SquareMatrix with two instance variables: an integer named
size that contains the size of the matrix, and a two dimensional array named
elements that contains the elements of the matrix. Write the following methods:
• Constructor: takes an integer parameter for size, checks that it is a value
between 1 and 5 inclusive, and creates the two dimensional array elements
with size rows and size columns and initializes it with random values
between 0 and 9 inclusive. If the size parameter is out of range, size should
be initialized to 5
• String toString(): returns a string containing the elements of the matrix
properly 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 and col define a
valid location and sets the corresponding element to value
• int getElement(row, col): checks if row and col define a valid location and
return the value of the corresponding element; if the location is invalid,
return -1
• Draw a UML diagram for your program. Scan it using a scanner app on
your phone, or take a clear picture. Save as pdf.
2. Write an java application called Driver which calls each method of the SquareMatrix class at
least once.
Notes:
1. You will have to code two separate files.
2. Add a comment on top of each method, describing what that method does.

file name is " SquareMatrix.java "
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 6 images









