954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Koch Curve Help Please

Hi. I am kinda new to java and I really need help on this program that I have been assigned. Here is the assignment:

Assignment:
Write a KochCurve program that uses DrawingTool and provides a drawKochCurve method for drawing Koch curves. Each drawKochCurve method can take the number of levels and an initial size as its parameters.

Somehow, my code compiles but when I run it, nothing shows up. Can someone please help me. I would really appreciate it.

import gpdraw.*;

public class KochCurve {
    private DrawingTool pen;
    private SketchPad paper;
    
    public KochCurve(){
        paper = new SketchPad(500,500);
        pen = new DrawingTool(paper);
    }
    
    public void drawKochCurve(int level, int length) {
        if (level < 1)
            pen.forward(length);
        else {
            drawKochCurve(level - 1, length / 3);
            pen.turnLeft(60);
            drawKochCurve(level - 1, length / 3);
            pen.turnRight(120);
            drawKochCurve(level - 1, length / 3);
            pen.turnLeft(60);
            drawKochCurve(level - 1, length / 3);
        }
    }
    
    public static void main(String[] args) {
        KochCurve curve = new KochCurve();
        curve.drawKochCurve(6,300);
    }
}
Kurosaki
Newbie Poster
5 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

Your program is working, but no part of this problem includes showing the drawing on the screen!

Dukane
Posting Whiz in Training
295 posts since Oct 2006
Reputation Points: 45
Solved Threads: 29
 

if the DrawingTool class draws with the forward() method it might...
I've never heard of that class so it's hard to tell.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Nevermind. I found out what was wrong with my code. Thanks anyway.

Kurosaki
Newbie Poster
5 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 
Nevermind. I found out what was wrong with my code. Thanks anyway.

I'm doing the same exact lab and i'm having difficulty with it also. What did u change 2 make it work?

indiancoder603
Newbie Poster
2 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

do your own thinking kid...

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
do your own thinking kid...


no seriously i had the same problem. i tried 2 do the lab first but i got no where. i realized there is a floating point error so u have to change the ints to doubles.

indiancoder603
Newbie Poster
2 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

how can u say that when you were at one point asking the same thing!

gods_angel
Newbie Poster
2 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You