[SOLVED] SOLVED:Thread Lab

15.00 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (2 votes)

Start with the Car, CarPanel and CarFrame provided.

Add a CarQueue class that maintains a queue of random directions that the car should go.

1. There is an addToQueue method that has a class that implements runnable, define the run method (add random directions into the queue and then sleep), creates an instance of the runnable object, creates a thread and starts the thread.

/** Adds 0,1,2 or 3 to queue

* 0 = up

* 1 = down

* 2 = right

* 3 = left

*/

2. It also has a deleteQueue method that returns an Integer;

3. In your constructor, place 5 or 6 numbers in the queue so that when the animation starts – there will be something to retrieve from the queue

Modify the run method of the startAnimation in CarPanel so that the car will go to the right, left, up or down depending on what is retrieved from the CarQueue. The cars should go in the opposite direction if they hit a boundary.

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.