Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

************PLEASE DO IT RECURSIVELY************ ******* PLEASE DO IT USING RECURSIVE FUNCTION.... public class PE1 { public static void main(String[] args) { /* A canvas should

************PLEASE DO IT RECURSIVELY************

image text in transcribed

*******PLEASE DO IT USING RECURSIVE FUNCTION....

public class PE1 {

public static void main(String[] args) {

/* A canvas should be created for drawing.

* All the shapes should be drawn on the canvas.

* The bottom left coordinate of the canvas is (0,0)

* The top right coordinates of the canvas is (1, 1)

* The input parameter to Draw() constructor is the

* title of the canvas.

*/

Draw blankCanvas = new Draw("Programmign 1");

/* To draw a point, point function is called with proper parameters:

* point(x_coordinate_of_point, y_coordinate_of_point)

*/

blankCanvas.point(0.7, 0.7);

/* To draw a circle, circle function is called with proper parameters:

* circle(x_coordinate_of_center, y_coordinate_of_center, radius)

*/

blankCanvas.circle(0.5, 0.5, 0.5);

/* To draw a square, square function is called with proper parameters:

* square(x_coordinate_of_center, y_coordinate_center, sides_half_length)

*/

blankCanvas.square(0.5, 0.5, 0.4);

/*

* To change the color of the pen, setPenColor is used with three numbers that are in [0, 255] range.

* All the colors can be made as a combination of red, green and blue.

* The parameters show the richness of red, green and blue of a color.

* For example setPenColor(new Color(0, 0, 0) sets the color of the pen

* to black and setPenColor(new Color(255, 255, 255) sets the color to

* white.

*/

blankCanvas.setPenColor(new Color(150, 150, 150));

/* To draw a line, line function is called

* with proper parameters:

* line(x_coordinate_of_center, y_coordinate_center, sides_half_length)

*/

blankCanvas.line(0.0, 0.5, 1, 0.5);

}

/**

* This method recursively draws 4 squares, whose center falls on a corner of

* previously drawn square. The side of the square is half as much as the side of the

* square that is drawn in previous round.

* @param x is the x-coordinate of the square

* @param y is the y-coordinate of the square

* @param halfLength is half the size of the square's side

* @param order is the number of the rounds by which a set of squares is drawn

* @param page is the canvas on which the squares are drawn.

* @return a list of the center of smallest squares that are drawn..

* The coordinates should be cut to one decimal point. For example:

* 0.39876543210 is cut to 0.3

*/

public static String squares (double x, double y, double halfLength, int order, Draw page) {

// your code goes here. Task 2

return "";

}

Task 2: For this task, you are required to implement a recursive method that draws a set of squares where the center of one square falls on one corner of another square. The number of squares that should be drawn is given as an input parameter called order. If the order is one, then only one square is drawn. If the order is two, then 5 squares will be drawn when on each corner of the central square another square is drawn, whose side length is half the central square's side length. Please see the picture below that shows the drawing for order = 1 to 4. The output of this method is a list of the coordinates of the smallest squares that are drawn. More information on this method can be found in the javaDoc. order = 1 order = 2 order = 3 order = 4 pppp 14 256 256 GH 555 OG9O69 Sample Call: PE1.squares (0.5, 0.5, 0.2, 2, blankCanvas); Corresponding Output: [0.7, 0.7][0.7, 0.3] [0.3, 0.7][0.3, 0.3]

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 Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago