Programming Assignment 3
Wrapper Classes, Text Processing, and Recursion with Merge Sort
Code Review for Jade Cheng
Build Results
No errors; no warnings
Requirements Verification
All source code should be submitted in one file, and that file should be named according to the following pattern: LastFirstX.java
, where Last
is the student’s last name, First
is the student’s first name, and X
is the assignment number.
For example, student John Doe
would submit DoeJohn3.java
for programming assignment 3.
PASS.
The first lines of the submitted file should include a comment with the following information and format:
/** * A short description of the program. * * @author Last Name, First Name * @assignment CSCI 2912 Assignment X * @date Date */
PASS.
The submitted file should be emailed to ycheng@hpu.edu.
PASS.
The subject line of the email sent to the instructor should follow the pattern: [2912] assignment number
.
For example, for assignment 3, student John Doe would write “[2912] assignment 3
” as the subject line of his submission email.
PASS.
The submission email sent to the instructor should include exactly one attachment, the Java implementation file. Students should not attach any other files to their submission email.
PASS.
The implementation file must include JavaDoc for all definitions: classes, interfaces, fields, methods, enumerations, and so on.
PASS.
You will implement a Java console application that sorts and prints floating-point values read from a text file.
PASS.
The application determines the name of the text file from the command-line arguments.
PASS.
If the user supplies no arguments, or if the user supplies two or more arguments, the application terminates after writing to Standard Error, “Invalid command-line arguments.”.
PASS.
The application loops over every line of the input file.
PASS.
For every iteration, the application parses the line as a Double
.
PASS.
If a line from the file is empty, the application terminates after writing to Standard Error, “Empty line encountered.”.
PASS.
If a line from the input file contains anything other than one valid Double
, the application terminates after writing to Standard Error, “Invalid line encountered: 'XXX'”, where 'XXX' is the contents of the first invalid line.
PASS.
If any other I/O error occurs while reading the input file, the application terminates after writing to Standard Error, “Failed to read input file: XXX”, where XXX is the value returned by Exception.getMessage()
.
PASS.
The application stores the parsed values from the text file into a collection of type ArrayList<Double>
.
PASS.
Once all values are added to this collection, the application creates an array of type double[]
that is the same length as the size of the collection.
PASS.
The application “unboxes” the values from the collection and stores the corresponding primitive values into the array.
PASS.
The application sorts the array using the recursive MergeSort algorithm.
PASS.
The implementation defines a method with the following signature to start the sort:
static void mergeSort(double[] values)
PASS.
The mergeSort(double[])
method allocates a scratch array that is the same size as the input array.
PASS.
This method then calls a method with the following signature to perform the recursive portion of the algorithm:
static void mergeSort( double[] values, double[] scratch, int min, int max)
PASS.
Once the sort finishes, the application writes the contents of the sorted array to Standard Output.
PASS.
Each value in the array is printed consecutively as lines of output.
PASS.
When all values have been printed, the appilcation terminates immediately without displaying any additional information.
PASS.
General Observations
Note these observations will not affect the grade.
No all test cases included in the code review Sample Execution section directly corresponds to point deduction.
Sample Execution
$ java ChengJade3 input-10.txt
-888211.1605259295 -839492.6177241252 -796261.9297413327 -644194.1516219857 -379043.67094740574 -25647.904978653325 -16632.28254947069 309635.67545154213 713003.7111956163 762163.0955897978
$ java ChengJade3
Invalid command-line arguments.
$ java ChengJade3 file1.txt file2.tx
Invalid command-line arguments.
$ java ChengJade3 missing.txt
Failed to read input file: missing.txt (No such file or directory)
$ java ChengJade3 .
Failed to read input file: . (No such file or directory)
$ java ChengJade3 one-dot-two-dot-three.txt
Invalid line encountered: '1.2.3'.
$ java ChengJade3 bad-line.txt
Invalid line encountered: 'two'.
$ java ChengJade3 missing-line.txt
Empty line encountered.
$ java ChengJade3 two-values-one-line.txt
Invalid line encountered: '32206.916666862595 202214.0167762111'.
$ java ChengJade3 no-values.txt
$ java ChengJade3 one-value.txt
-295779.0822148841
$ java ChengJade3 ten-zeros.txt
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
$ java ChengJade3 input-100.txt
-998326.8595259386 -989408.8044998769 -983065.8346825077 -943019.2965369031 -928335.2431083327 -920318.1160085173 -918394.5595313865 -912628.0044230778 -885048.4223227528 -860346.4411677731 : 803700.8121081387 814865.480997835 849613.2222217893 879640.7846536716 897409.1877907796 903030.6322012142 945610.3458635272 950777.9582715404 963769.1056427028 979115.4530355601
$ java ChengJade3 input-1000.txt
-996346.1787669841 -995689.4598003131 -992533.073824536 -991537.8272126288 -988902.7793058364 -987635.3635979282 -985813.936202083 -983238.7512088792 -981770.5766075291 -981055.8817286383 : 967056.0787500457 970355.4238566799 978122.8090351489 988481.8252230101 991692.5415023902 992140.1390440486 992330.6294650194 995775.1596994501 996294.5709995305 998343.289964667
$ java ChengJade3 input-10000.txt
-999659.5478344935 -999613.2070814496 -999581.9918474474 -999103.2112438192 -998985.5043984993 -998851.4951166552 -998593.3898941225 -998517.5855187286 -998447.4847103284 -998353.9213703101 : 996922.3614430977 997184.2465856617 997353.015810882 998764.3498125954 999245.8282326407 999370.8281372498 999432.2489229289 999605.2765620276 999859.6551518273 999885.1099960832
$ java ChengJade3 input-100000.txt
-999983.0731669184 -999958.8010745589 -999947.6883622973 -999925.8416341653 -999922.5880987486 -999914.6283749006 -999897.7568574584 -999869.4821669993 -999842.3974161063 -999838.0003868769 : 999835.5288978885 999851.9114911661 999859.5988013856 999864.6053427228 999866.9501269131 999871.9518094807 999898.4421132738 999927.104136604 999975.4944079395 999976.0348586875
$ java ChengJade3 input-1000000.txt
-999994.8568903183 -999992.606130832 -999987.7283463523 -999987.0556262493 -999985.4927229845 -999982.5431694613 -999982.3845140607 -999981.3091569765 -999979.430183136 -999975.7797005803 : 999989.8017412461 999991.1978514962 999991.4083987417 999991.7653671975 999993.5188617645 999993.7846509034 999996.3352681 999997.8634369384 999998.8899417907 999999.5512709095