0

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);
    }
}
5
Contributors
7
Replies
8
Views
10 Years
Discussion Span
Last Post by gods_angel
0

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

0

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

0

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

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?

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.