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.
Three Java classes are involved, two of which is provided in full:
The student is to finish the development of this class.
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 |
This activity is to solve Problem 2 on the midterm exam. Two Java classes are involved, the second of which is provided in full:
The loop in the partition() method must have as an invariant these conditions:
where N is shorthand for A.length. As a diagram, that looks like this:
0 j k N +------------+-----------+------------+ A | ?? | all RED | all BLUE | && 0<=j<=k<=N +------------+-----------+------------+ |
It expects to receive as a command-line argument (or what jGrasp calls a run argument) a string of R's and B's, standing, respectively, for "RED" and "BLUE".
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.