CMPS 144L Fall 2023
Lab #8 (Oct. 19)

Activity #1: Point Sorting

This activity asks you to solve Problem 4 of the midterm exam, but this time to do it on your computer rather than with paper and pencil.

Five Java classes are involved, three of which are provided:

The PointSorterTester program makes use of a "hard-coded" array of Point values. A successful run of that program will produce this output:

Array before sorting:
[(3.5,6.2), (-4.8,0.4), (0.0,0.0), (-12.5,1.75), (-2.0,-3.5), (0.5,6.3), (8.25,4.7), (1.25,2.0)]

After sorting by x-coordinates
[(-12.5,1.75), (-4.8,0.4), (-2.0,-3.5), (0.0,0.0), (0.5,6.3), (1.25,2.0), (3.5,6.2), (8.25,4.7)]
That is correct!

After sorting by distances from origin
[(0.0,0.0), (1.25,2.0), (-2.0,-3.5), (-4.8,0.4), (0.5,6.3), (3.5,6.2), (8.25,4.7), (-12.5,1.75)]
That is correct!

Goodbye.

If the sort() method does not work as intended, the That is correct! message will be replaced by one or more messages indicating an error.


Activity #2: Counter Who Remembers Max

This activity asks you to solve Problem 5 of the midterm exam, but this time to do it on your computer rather than with paper and pencil.

Three Java classes are involved, two of which is provided in full:

To illustrate what the tester program does, here is an example run. Notice that the user supplied the string "DDIIIIDDIDIIIDDDDI" to it as the command line argument.

$ java CWRM_Tester DDIIIIDDIDIIIDDDDI
Initially: Count value: 0; Max reached: 0
After decrementing: Count value: -1; Max reached: 0
After decrementing: Count value: -2; Max reached: 0
After incrementing: Count value: -1; Max reached: 0
After incrementing: Count value: 0; Max reached: 0
After incrementing: Count value: 1; Max reached: 1
After incrementing: Count value: 2; Max reached: 2
After decrementing: Count value: 1; Max reached: 2
After decrementing: Count value: 0; Max reached: 2
After incrementing: Count value: 1; Max reached: 2
After decrementing: Count value: 0; Max reached: 2
After incrementing: Count value: 1; Max reached: 2
After incrementing: Count value: 2; Max reached: 2
After incrementing: Count value: 3; Max reached: 3
After decrementing: Count value: 2; Max reached: 3
After decrementing: Count value: 1; Max reached: 3
After decrementing: Count value: 0; Max reached: 3
After decrementing: Count value: -1; Max reached: 3
After incrementing: Count value: 0; Max reached: 3


Activity #3: Red/Blue Partitioning

This activity is to solve Problem 2 on the midterm exam. Two Java classes are involved, the second of which is provided in full:

To illustrate what the tester program does, here is an example run. Notice that the user supplied the string "BBRBRRRBRBRR" to it as the command line argument.

$ java RBPartTester BBRBRRRBRBRR
Original Array: BBRBRRRBRBRR
After partitioning:
  Red segment: RRRRRRR
  Blue segment: BBBBB

The partition() method itself verifies, before and after each of its loop iterations, that the intended loop invariant evaluates to true. If not, an error message is produced.