Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a class named PrintNumbers that implements the Runnable interface. Add

ID: 3640467 • Letter: 1

Question

1. Write a class named PrintNumbers that implements the Runnable
interface. Add a field of type boolean called keepGoing and a constructor that initializes keepGoing to true.

2. Add a method to the PrintNumbers class called stopPrinting() that
assigns the keepGoing field to false.

3. Within the run() method, write a while loop using
System.out.printl(), which prints out the numbers 1, 2, 3, 4, and so
on for as long as the keepGoing field is true. In between printing
each number, the thread should sleep for 1 second.

4. Save and compile the PrintNumbers class.

5. Write a class named Print that contains main(). Within main(),
instantiate a PrintNumbers object. Instantiate a Thead object that
will be used to run the PrintNumbers object in a separate thread and
then start the thread.

6. The Print program will take in a single command-line argument to
represent the number of milliseconds that the main() thread will
sleep. Parse this argument into an int and then have the main()
thread sleep for that amount of milliseconds.

7. When the main() thread wakes up, have it invoke the stopPrinting()
method on the PrintNumbers object.

8. Save, compile, and run the Print program. Don’t forget to pass in an
int to represent how long the program will run in milliseconds.

Explanation / Answer

DON'T FORGET TO RATE...

Solution : http://dl.dropbox.com/u/56476562/Print.html

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote