javax2007 0 Newbie Poster

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

import TurtleGraphics.StandardPen;
 import java.awt.Color;
 import TerminalIO.KeyboardReader;
 
public class TestCar 
{
 
 public static void 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;
 
 
public class Car {
 
 private StandardPen pen; 
 private double 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; 
 }
 
 public void drawCar()
  {
    drawRectangle (-150,75, 300, 150);
    drawRectangle (-50, 125, 100, 50);
    drawCircle (124, -230, 40);
    drawCircle (-124, -230, 40);
 
  }
 
  public void 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);
 
  }
 
  public void 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);
    }
 }
 
 public void 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:

public void oneSec() 
   {
   try 
   {
   Thread.currentThread().sleep(1000);
   }
   catch (InterruptedException e) 
   {
     e.printStackTrace();
   }
   }

If anyone can help it'd help alot thanks

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.