CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades | Students

Lab #13 (Exercise 14-1)

Create a Number Finder application

Due Date: Monday of Week 5
10 points

In this lab, you'll create an application that generates a random number between 0 and 999, and then uses four threads to search for the number. When one of the threads finds the number, it should print a message on the console. The output from this application should look like this:



  1. Open the NumberFinderThreadApp class. Review its code to see that it generates a random number between 0 and 999 and then displays it at the console.
  2. Add a class named Finder that extends the Thread class to the NumberFinderThreadApp file. Then, add a constructor to this class that accepts three parameters: the number to search for, the number where the search should begin, and the number where the search should end.

  3. Add a run method to the Finder class that searches for the number. This method should use a for loop to check each value in the specified range to determine if it matches the target value. If a match is made, the thread should display a message like the one shown above and terminate. Every ten times through the loop, the thread should yield to other threads.

  4. Add acode to the main method to create and start the four threads. The threads should check the following ranges: thread0, 0-249; thread1, 250-499; thread2, 500-749; and thread3, 750-999.

  5. Compile the program. Then, run it two or more times to be sure it works correctly.

Include in your program the following comments:
  • Name of program
  • Team's name with all the names of the members (e.g. Team A: John Doe, Jane Smith, etc.)
  • Current Date
  • Computer system and compiler you are using
  • Brief description of the program

Compile and run the Java program.

Take a screen capture by hitting simultaneously the keys Alt and Print Screen (Prt Sc) of the output results (console) and paste it in MS Paint. Save it as a gif file.

When you are ready, upload the java program and the gif file by clicking the link below:

Upload Lab

I cannot grade if I don't get the files and receive your email.