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

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use 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);...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$60.00
for this solution

or FREE if you
register a new account!

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