QuestionQuestion

Write a program that simulates car racing. The car moves from left to right. When it hits the right end, it restarts from the left and continues the same process.

You can use a timer to control animation. Redraw the car with a new base coordinates (x,y). Also let the user pause/resume the animation with a button press/release and increase/decrease the car speed by pressing the UP and DOWN arrow keys.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Car extends Pane{
    public final double radius = 5;
    private double x = 0, y = -20;
    private double dx = 1, dy = 1;
    private double length = 50;
    private Rectangle rec = new Rectangle(x, y);
    private Timeline animation;
    private boolean firsttime = true;
    private Circle c1 = new Circle(x , y, radius);
    private Circle c2 = new Circle(x , y, radius);
    private Polygon p = new Polygon();
    ObservableList<Double> list; // list of points of polyton
   
    public Car() {
       //set shapes
       rec.setFill(Color.LIGHTBLUE);
       rec.setHeight(10);
       rec.setWidth(length);      
       getChildren().add(rec);
      
       c1.setFill(Color.BLACK);
       getChildren().add(c1);
      
       c2.setFill(Color.BLACK);
       getChildren().add(c2);
      
       p.setFill(Color.BLUE);
       getChildren().add(p);...
$60.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats