Having trouble with drawing a Car with TurtleGraphics

hey guys

i need help on a program that should draw a car, erase it, and draw it again but in a different spot on the window. Now I have all of this except when the car is drawn again the wheels aren't moved with the car.

Heres the main:

import TurtleGraphics.StandardPen;

import java.awt.Color;

import TerminalIO.KeyboardReader;

publicclass TestCar

{

publicstaticvoid main(String[] args)

{

KeyboardReader reader =new KeyboardReader();

Car firstCar =new Car();

firstCar.drawCar();

reader.pause();

firstCar.eraseCar();

reader.pause();

Car secondCar =new Car(100, 100);

secondCar.drawCar();

}

}

Here is the class:

import TurtleGraphics.StandardPen;

import java.awt.Color;

publicclass Car{

private StandardPen pen;

privatedouble xPosition, yPosition;

public Car ()

{

xPosition = 0;

yPosition = 0;

pen =new StandardPen();

pen.setColor(Color.red);

}

public Car(double x,double y)

{

this();

xPosition = x;

yPosition = y;

}

publicvoid drawCar()

{

drawRectangle (-150,75, 300, 150);

drawRectangle (-50, 125, 100, 50);

drawCircle (124, -230, 40);

drawCircle (-124, -230, 40);

}

publicvoid drawRectangle (double x,double y,double length,double width)

{

pen.up();

pen.move(x + xPosition, y + yPosition);

pen.down();

pen.setDirection(270);

pen.move(width);

pen.turn(90);

pen.move(length);

pen.turn(90);

pen.move(width);

pen.turn(90);

pen.move(length);

}

publicvoid drawCircle(double x,double y,double radius)

{

double side = 2.0 * Math.PI * radius / 120.0;

pen.up();

pen.move((xPosition + x + radius), ((yPosition + y) - side)/ 2.0);

pen.setDirection(90);

pen.down();

for(int i = 0; i< 120; i++)

{

pen.move(side);

pen.turn(3);

}

}

publicvoid eraseCar()

{

pen.setColor(Color.white);

drawCar();

pen.setColor(Color.red);

}

}

Also the car is supposed to move across the screen once drawn the second time but i haven't figured that out yet. Maybe with a thread:

publicvoid oneSec()

{

try

{

Thread.currentThread().sleep(1000);

}

catch (InterruptedException e)

{

e.printStackTrace();

}

}

If anyone can help it'd help alot thanks

[4989 byte] By [cupOfJava2008a] at [2007-11-27 6:14:29]
# 1

Yes, I was just thinking Java needed a Logo port...

I think the best thing you can do to debug this is add some System.out.prinltn statements to some of your methods. Especially draw circle and draw rectangle. The obvious answer is that your pen is not positioned where it needs to be. Although it is not clear to me why...

cotton.ma at 2007-7-12 17:24:02 > top of Java-index,Java Essentials,Java Programming...
# 2
thanks i tried putting printlns but i dont think i can find the problem that way because the ouput is in a seperate window not in the black box that it is usually in since im using turtleGraphics. Thanks for your help anyways though
cupOfJava2008a at 2007-7-12 17:24:02 > top of Java-index,Java Essentials,Java Programming...
# 3
i was thinking about how the wheels dont move with the box car but they still do move do you think that the drawCircle method has something wrong in it. maybe the coordinates arent being calculated correctly. im not sure though how to debug this
cupOfJava2008a at 2007-7-12 17:24:02 > top of Java-index,Java Essentials,Java Programming...
# 4
any suggestions guys on how to move the car or fixing the wheels?
cupOfJava2008a at 2007-7-12 17:24:02 > top of Java-index,Java Essentials,Java Programming...
# 5
please help me out im kinda on a stretch
cupOfJava2008a at 2007-7-12 17:24:02 > top of Java-index,Java Essentials,Java Programming...
# 6
help
cupOfJava2008a at 2007-7-12 17:24:02 > top of Java-index,Java Essentials,Java Programming...
# 7

i fixed the part about the wheels now but im stuck on how to make the car move on the turtleGraphics window once it is drawn the second time.

Would this thread help it at all?

public void oneSec()

{

try

{

Thread.currentThread().sleep(1000);

}

catch (InterruptedException e)

{

e.printStackTrace();

}

}

cupOfJava2008a at 2007-7-12 17:24:02 > top of Java-index,Java Essentials,Java Programming...