Question: Write a Java method that draw rectangles on a given matrix. The method heading should be public static void drawRectangle(int[][] matrix, int x, int y,

Write a Java method that draw rectangles on a given matrix. The method heading should be public static void drawRectangle(int[][] matrix, int x, int y, int height, int width, int borderColor, int fillColor, boolean filled) where:

matrix is the matrix on which the rectangle is drawn

x is the 0-based row number of the top-left corner of the rectangle to be drawn

y is the 0-based column number of the top-left corner of the rectangle

height is the height of the rectangle width is the width of the rectangle

borderColor is the value on the boundaries of the rectangle

fillColor is the value inside the rectangle, if it is filled

filled determines if the rectangle is filled or not.

Please refer to the example for a demonstration on how the method call affects the matrix.

Please could you please explain with each line code and algorithm.

Example: int[][] myMatrix = new int[10][10];

drawRectangle(myMatrix, 3, 5, 5, 4, 3, 3, true);

drawRectangle(myMatrix, 1, 1, 8, 6, 1, 19, false);

Before:

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

After:

0 0 0 0 0 0 0 0 0 0

0 1 1 1 1 1 1 0 0 0

0 1 0 0 0 0 1 0 0 0

0 1 0 0 0 3 1 3 3 0

0 1 0 0 0 3 1 3 3 0

0 1 0 0 0 3 1 3 3 0

0 1 0 0 0 3 1 3 3 0

0 1 0 0 0 3 1 3 3 0

0 1 1 1 1 1 1 0 0 0

0 0 0 0 0 0 0 0 0 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!