CMPS 144L Lab Activity
Computing the Min and Max of an Array using Threads

Here are some Java classes, the first of which it is your task to complete:


Dialog with ParMinMaxTester

User input is shown in boldface. The program first prompts the user to enter the length of the array that is to be the subject of the computation. Then it asks the user to enter lower and upper bounds on the integer values to be placed into the array. Finally, the user provides a seed that is used in establishing an instance of java.util.Random that is used for populating the array with pseudo-randomly generated integer values.

The lines of output that report the minimum and maximum values in specified segments of the array are simply for the purpose of narrating the program's execution, which could aid in debugging.

Each thread produces one such line of output immediately after it has identified the minimum and maximum in the array segment for which it was "responsible". Leaf threads (i.e., ones not having any child threads) describe their segments as SHORT; threads with children describe their segments as LONG.

Whether an array segment is long or short depends upon its length as compared to the class constant LENGTH_THRESHOLD.

Enter array length: 60
Enter lower bound value: -15
Enter upper bound value: 39
Enter random seed: 9
Array: [14, 36, 18, 30, -6, 27, -7, -9, 23, 3, 26, 1, 26, -12, -5, 3, 26, 
-7, 34, 39, 11, -4, 1, 32, 16, 14, 32, -7, 28, 37, 1, 0, -14, 32, 25, 16,
23, 25, 15, 16, -8, 32, -10, -10, -11, 26, 39, 37, 20, 28, -12, -2, 23, 9,
-2, 1, 15, 12, 7, 3]
In SHORT range [0..7) the min is -7 and the max is 36
In SHORT range [15..22) the min is -7 and the max is 39
In SHORT range [7..11) the min is -9 and the max is 26
In SHORT range [45..52) the min is -12 and the max is 39
In SHORT range [11..15) the min is -12 and the max is 26
In SHORT range [30..37) the min is -14 and the max is 32
In LONG range [7..15) the min is -12 and the max is 26
In LONG range [0..15) the min is -12 and the max is 36
In SHORT range [52..56) the min is -2 and the max is 23
In SHORT range [56..60) the min is 3 and the max is 15
In SHORT range [37..41) the min is -8 and the max is 25
In SHORT range [41..45) the min is -11 and the max is 32
In SHORT range [22..26) the min is 1 and the max is 32
In LONG range [37..45) the min is -11 and the max is 32
In LONG range [30..45) the min is -14 and the max is 32
In SHORT range [26..30) the min is -7 and the max is 37
In LONG range [22..30) the min is -7 and the max is 37
In LONG range [15..30) the min is -7 and the max is 39
In LONG range [0..30) the min is -12 and the max is 39
In LONG range [52..60) the min is -2 and the max is 23
In LONG range [45..60) the min is -12 and the max is 39
In LONG range [30..60) the min is -14 and the max is 39
In LONG range [0..60) the min is -14 and the max is 39

ParallelMinMax reports that the min and max are -14 and 39