Many thanks,

as usual, I would appreciate it is someone could explain/help me get to the right answer rather than just giving it to me.

This is basically a translation from words to pseudo code. Now all that you will need to do is implement drawSimpleLine and rotate.

Considering you will be using Swing for this, you can do the drawing with a JPanel:

Graphics.drawLine will be your friend here.

One more hint: the Graphics object is usually an instance of Graphics2D. This class has methods to translate and rotate it which may be able to help you.

[ September 28, 2008: Message edited by: Rob Prime ]

Some more hints, after I've implemented this:

1) make the length parameter a double. Otherwise the rounding down will cause the figure to shrink horizontally.

2) don't go higher than order 6; on my machine, order 7 takes between half a second and a full second to paint. Order 8 takes around 4 seconds, 9 goes to 13+ seconds and 10 takes over a minute.

[ September 28, 2008: Message edited by: Rob Prime ]

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

What do you think of using recursion in real life programs for naturally recursive problems? I mean from a performance perspective. Stack overflows etc?

Consider the usual Fibonacci algorithm which is exponential, but you can write algorithms quite simply which run in linear time, and there is a logarithmic time Fibonacci algorithm too. It is in Kaldewaij, A.,

*Programming: the derivation of algorithms*, Prentice Hall International series in computer series, Prentice Hall International, 1990. ISBN 0132041081 250 pages, I think page 98-99.

Originally posted by Campbell Ritchie:

It is in Kaldewaij, A.,Programming: the derivation of algorithms, Prentice Hall International series in computer series, Prentice Hall International, 1990. ISBN 0132041081 250 pages, I think page 98-99.

Great book by the way, it's what we started with in University.

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

Recursion's perception also suffers from there being bad examples for it out there. Fibonacci numbers are a particularly egregious example, since it leads to tree recursion -which is much worse than linear recursion-, while a simple iterative solution is available.

Recursion depth (and the stack problems if it's too deep) is a real concern, but what's possible depends so much individual circumstances that dismissing recursion out of hand seems a bad idea.

Just my 2 cents.

Update: Pretty similar to Campbell's 2 cents, I see now :-)

[ September 29, 2008: Message edited by: Ulf Dittmer ]

Originally posted by Ulf Dittmer:

Pretty similar to Campbell's 2 cents, I see now :-)

Campbell's 2 pence, please.

Originally posted by Campbell Ritchie:

Campbell's 2 pence, please.

Which these days are better than 2 cents worth of opinion, I take it.

Pence > euro cents > dollar cents

Unfortunately for me, because I like to buy stuff online in the UK regularly. It would be sooo much better for me if the Pound became less valuable than the Euro

As it is, 1 Euro is still somewhere between 0.70 and 0.80 Pounds.

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

Last time I went to Holland 1� was worth �0.64.Originally posted by Rob Prime:

1 Euro is still somewhere between 0.70 and 0.80 Pounds.

But enough of this currency talk now! Back to recursion!

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

It is sorta covered in the JavaRanch Style Guide. |