Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions