CSE 8B:
Introduction to Computer Science: Java
(Winter, 2006)
Home | Syllabus |
Schedule | Exams |
Programming Assignments
Programming Assignment 5
Due Monday, February 20 at 11:59 PM.
Last modified:
Wed., Feb 15, 3:50: updated Overview to correctly show no input redirection (<) when calling java Sort.
Previous modifications:
Overview
You'll be writing a program that sorts input lines.
The program will read in a text file and will output another text file which is the original text file with all the lines sorted.
You'll run the program with
java Sort infile outfile
Input/Output
The input could be any text file.
The output is a text file (if the file doesn't exist: create it; if it already exists, overwrite it).
Your output must match exactly the output we are expecting.
I recommend you test your application with:
java Sort testInput.txt myOutput.txt
diff myOutput.txt testOutput.txt
If diff reports any difference, your output doesn't match. If diff doesn't print anything,
that means your output (myOutput.txt) is identical to the provided testOutput.txt.
Requirements
- The program will need to work with any number of lines.
However, your initial array of lines should start with a size of 10; reallocate it as needed.
- If an error occurs while opening the files,
print out to System.err an error of the form: can't open: specific error.
Errors might include a missing input file, or a read-only output file.
To make a file read-only, do: chmod 444 file
- If the user doesn't input two arguments to the command-line, issue an error to System.err
of the form:usage: java Sort inputFile outputFile
Provided files
All files are in ~/../public/P5.
There are several test inputs and outputs.
Unit Testing
Although I highly suggest you use Test-Driven Development to develop your application, and
have a complete set of unit tests, it is not required.
If you do use unit testing, you will probably wanto to use StringInputStream and StringOutputStream to test, rather than the file-based ones.
Hints
- Feel free to use useful standard java methods for sorting and coyping (a google search can help find useful methods).
- Write your Sort class so that it can take input from any InputStream and write to any
OutputStream. Although the main will be concerned with files, the rest of the class should
work with any kind of stream, not just file-based streams.
- Make sure to test error cases (input file missing and output file read-only are good tests). To make a file readonly: chmod 444 file
- To handle an unknown number of input lines, allocate a new array when the existing array is full. Make it twice as big as the old one and copy the contents of the old array into the new array.
- The String class has a compareTo method that'll tell whether one string compares before another.
Turnin
Create a directory on ieng6 with the following file:
To turn in your assignment, cd to that directory and run the command
bundleP5
and carefully follow the dialog.
If it is before the due deadline and all necessary assignment files are present,
this will turn in your solution files.
You can run bundleP5 more than once if you want; only the last one will count.
Grading
We'll be running your sort program from the command-line with input of our own, and checking the output, which will
need to match identically (we'll be doing a diff from the command-line).
The assignment is worth 20 points:
- 6 points: Sort that runs the sample input we've provided correctly. Note that it must be solving
the sort problem, not just hardwired to look for our sample input, and regurgitate the needed output.
- 6 points: Sort that runs some new input correctly.
- 4 points: handling errors as specified.
- 4 points: Style points for your class. Good naming, not repeating yourself, correct indentation,
not exceeding 80 characters per line, good organizing of methods into classes, etc.
As always, an additional 5% (1 point) is available if you turn the assignment in at least 24 hours early.