9.3. Exercises

9-1.

Once upon a time, there was a sensible straight line who was hopelessly in love with a dot.

With these words, we are introduced to the hero of Norton Juster's delightful story The Dot and the Line, who eventually discovers the versatility of his linear form and lives "if not happily ever after, at least reasonably so." As a way of demonstrating his newfound talents to the object of his affection, the Line assumes the following form:

Taking advantage of the fact that this diagram consists of several repetitions of the figure

drawn at various sizes and angles, write a Java program to generate the diagram. In this example, although recursion is not strictly necessary, it provides a simple way of generating the repeated figures.
9-2.Using the definitions of setLocation and drawLine as given in this chapter, complete the code for the Mondrian-style painting program described in Chapter 1. The difficulty lies in choosing some criterion for terminating the recursion. Ideally, the decision of whether to split a subcanvas should depend on the size of the canvas in some way; larger problems should be subdivided more often than smaller ones.
9-3.Modify the drawFractal program to generate the flea diagrams used in this text. Although the figures are similar in structure ...

Get Thinking Recursively with Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.