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);
    }
}
Member Avatar for Dukane

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

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

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

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?

do your own thinking kid...

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.