Write a method drawforest that draws the trees using the


Part A

As part of a package called Assign_3, write a Java class called Forest. For the first part, the class will draw a set of spokes on the display as shown below.

2257_img.png

Write a method called drawSpokes to draw the spokes. The method should take a double parameter that is the radius of the figure (i.e. the length of each spoke). There are 6 spokes, equally spaced around the center. To make Part B easier, make sure leave the turtle back where it started (i.e. at center facing right).

Part B

As the second part of the assignment, modify the Forest class written in Part A so that it draws a tree as seen below (the height is 80 and the canopy radius is 15).

523_img1.png

Write a method drawTree that draws the tree with a light gray trunk and a canopy. The method should take as parameters the height of the trunk and the radius of the canopy.

The trunk is a line drawn of specified height with pen width 10. The canopy is a set of spokes of the specified radius using a pen of width radius*2 using the method drawSpokes from Part A. The drawSpokes method should be modified to draw the spokes in green. Again, to make Part C easier, be sure to leave the turtle where it started.

Part C

As the third part of the assignment, modify the Forest class written in Part B so that it draws a forest of trees evenly spaced across the canvas as seen below:

1912_img2.png

Write a method drawForest that draws the trees using the method drawTree from Part B. The method takes as a parameter the number of trees to draw. Each tree has a randomly selected height between 40 and 100 and canopy radius between 10 and 20. The method is called with a random number of trees between 5 and 10. Use a FAST turtle.

Part D

As the final part of the assignment, modify the Forest class written in Part C so that it draws a forest in fall (i.e. some colored leaves) as seen below:

1787_img3.png

Write a method chooseColor that sets the pen color to green with a 75% probability and red with a 25% probability. Modify the drawSpokes method to call chooseColor rather than setting the pen color to green directly. To make the random selection of color, generate a random number between 0.0 and 1.0 (i.e. what random() returns). If the value is less than 0.75 choose green otherwise choose red. Suggestions:

• The separation into multiple methods with parameters as indicated is mandatory-for a good reason. Build up the program as outlined above rather than trying to get the final result. Procedural abstraction allows you to ignore the details of say how the tree is drawn, when writing the code to draw the forest.

• To make procedural abstraction effective, it is necessary to know where the turtle starts drawing and where it ends up after each method.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Write a method drawforest that draws the trees using the
Reference No:- TGS01145222

Expected delivery within 24 Hours