Project 3 consists of writing a Java application that sorts input data read from a file piped into the command line.
The program you develop as Project 3 will (a) read a sequence of
integers from stdin
as in Project 1, (b) store the
sequence in an array or doubly-linked list, (c) sort the input
sequence using one of three algorithms, and (d) output a header (shown
in the example below) and the sorted sequence to the screen. An
example of input and output is shown below.
When
the TAs test the program, the numbers will be read in
from a text file (inFile
), and the command line
will be as follows:
java Proj3 dswitch aswitch < inFile
dswitch
is one of the following switches:
-a
for array or -d
for doubly-linked list,
and aswitch
is one of the following switches:
-h
for histogram-sort, -i
for insertion-sort,
or -m
for merge-sort.
Also,
inFile
, a text file that you enter using a
word processor will be stored on disk. Your program will read the
input sequence by command-line piping of that file to stdin
.
More information about the test procedure is posted below under Example Test Procedure.
stdin
piped from a
text file whose name is specified on the command line. The
input file must be structured as a stream of integers, one
per line.
Step 2. Sort the input. For example, if the input is a sequence (11,44,33,55,22), then the sorted sequence will be (55,44,33,22,11). All sorting will be done in descending order, for simplicity.
Step 3. Write the following header to the screen:
your-name your-SSN 02 July 1999 COP3530-C99-Proj3Then, write the input and sorted sequences to the screen, ten integers per line. For example, if the input sequence is
4 2 9 3 5 6 7 8 10 11 1 12 14 13then the screen will display the following information after the header, and separated from the header by two blank lines:
Data Structure: Array Sorting Algorithm: (whatever one aswitch specifies) Numbers Read In: 14 Input Sequence: 4 2 9 3 5 6 7 8 10 11 1 12 14 13 Sorted Sequence: 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Hint: In Project 2, you developed a method that does this output function for each of the array and DLL classes. So, you can re-use this to generate output for each of the two sequences (input and sorted) that you must output for Project 3.
Step 4. Make sure that Steps 1-3 work for histogram-sort, insertion-sort, and merge-sort, using either array or DLL data structures.
Step 5. After you have tested and completed your program, use the submission procedure outlined below to submit your project.
Example Test Procedure. Type up a text file "inFile" in either Dos or Unix with one value per line, like this:
22 36 54 14 17 65
Now run your program this way:
java Proj3 dswitch aswitch < inFile
where dswitch
and aswitch
were described previously.
If the dswitch = -a
and aswitch =
-i
, your output would look like this:
John Smith SSN: 123-345-6789 02 July 1999 COP3530-C99-Proj3 Numbers read in: 6 Data Structure: Array Sorting Algorithm: Insertion-sort Input Sequence: 22 36 54 14 17 65 Sorted Sequence: 65 54 36 22 17 14For the dswitch
-d
, the Data Structure line should
read Doubly-Linked List
. The legend to put on the
Sorting Technique line for aswitch = -i
is
Histogram-sort
or for aswitch = -m
is
Merge-sort
.
Required Programming Procedure. Define each class in a
separate .java
file, with your master file as
Proj3.java
, where Proj3, which has a main method,
is the class name that the TAs will use to run your program. (It is
o.k. to have a main method in each class - the TAs are primarily
interested in the main
method in the Proj3
class.)
Other Hints on Programming Procedure. Use the following steps to guide your implementation of the Java version of the preceding program.
Hint 1. Get started early!!! Don't wait until the last two or three days, especially if you have not had much Java programming experience.
Hint 2. Decide what classes you will use (Hint: An
Array or Vector object might be useful, with
Reader class or objects, System class, etc.) Also,
it is strongly suggested that you adapt Dr. Sahni's classes as shown
in the text, to avoid undue programming effort. You can get code from
Dr. Sahni's Web page at
http://www.cise.ufl.edu/~sahni/dsaaj/
, but you must
not copy the code verbatim. You must adapt the code for your use.
After you have figured out what classes and objects to use, design
your Java class specification(s) on paper. Then (and only then)
should you start coding.
Hint 3. Code your class(es) and methods, testing them incrementally (i.e., one at a time). Get each one working before you go on to the next one. If you write your program all in one blob of code, you will assuredly have difficulty debugging it.
Hint 4. Try your program on different kinds of output (e.g., large and small inputs, with both negative and positive integers. If your code breaks, fix it until it works on all inputs. Use the pipe construct on the command line to get the input into your application.
Hint 5. Adapt the streaming I/O reader developed for Project 1, which must read 3-digit positive and negative integers from a file, one integer per line. If you developed another kind of reader for Project 1, you must modify it so it meets this specification. Deviations will be considered erroneous.
Hint 6. The TAs are here to help you with your problems. We have scheduled office hours throughout the week, with the exception of Wednesday afternoon (6/09), when the instructor and TAs will be working on grading exams, and the following Friday afternoon, when homeworks will be graded. Please feel free to ask the TAs any questions about your Java program.
Documentation. Illustrate your program with in-line comments, so the TAs know what you are doing. Consult your textbook and other Java programming references provided on the course Web page and elsewhere (e.g., Java books in library) for style guides.
Evaluation. Maximum score = 100 points, as follows:
CODE PRESENT & CLEAR 10 points max. For each of Insertion-, Histogram-, and Merge-sort classes: In-line Comments & Documentation 5 points max. Code compiles correctly 5 points max. File I/O works correctly 5 points max. Cmd-line switches work correctly 5 points max. Array sorted correctly 5 points max. DLL sorted correctly 5 points max. TOTAL POINTS PER CLASS = 30 x 3 SORTING CLASSES 90 points max. ---------------------------------------------------------------- TOTAL POINTS 100 points max.
For example, if you have only 60 percent the code needed, and it doesn't compile and isn't documented, you would get three of the five points allocated for the code being present. If the code is present, well documented, compiles, reads in data, and reverses the sequence correctly with correct output (but doesn't do anything else), then you could get as many as 20 points per class that had the preceding characteristics.
Submission Procedure. Please submit only your *.java files. You must be logged in to your CISE account to perform the submission procedure, which is described in detail at this link.
In summary, type in the following commands within your directory to submit all the java files for Project-2:
turnin -c cop3530 -p proj3 *.java
{Return}
Important Note: In case you have developed your programs on any environment other than the CISE Unix system, please test your program on a CISE Unix machine before submission. We will only be testing programs for grading purposes on the CISE Unix machines.
Special Note from Lloyd Noronha:
Before starting any programming project, please make sure that
there are no unnecessary files in your "dev" directory. Make sure you
only submit the files necessary for compiling and running your
project. You will lose points for compilation errors in any file you submit,
even if it is not relevant. We will compile and run your project as
follows :
So please make sure that you test run your project as above in your
directory just before your submission.
javac *.java
java Proj3 -a -i < inFile
Due Date. Submit the completed project by MIDNIGHT on Friday 02 July 1999. Projects submitted a day late will be penalized -10%; two days late: -20%, three days late: -30%, and four days late: -40% . Projects turned in more than four days late will not be accepted unless accompanied by a documented excuse (e.g., note from your physician or advisor).
This concludes the description of Project #3. Use the E-mail link at the top of this Web page to ask the TAs, if you have any questions about programming or grading.