Programming Assignment 1

File I/O, Console I/O, and Command-Line Arguments

Code Review for Jade Cheng

Build Results

No errors, no warnings.

Requirements Verification

REQ-SP1

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.

REQ-SP2

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.

REQ-SP3
The submitted file should be emailed to ycheng@hpu.edu.

PASS.

REQ-SP4

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.

REQ-SP5
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.

REQ-GG1
The implementation file must include JavaDoc for all definitions: classes, interfaces, fields, methods, enumerations, and so on.

PASS.

REQ-A1.1.1
You will implement a Java console application that opens and reads the contents of text files specified as command-line arguments.

PASS.

REQ-A1.1.2
For each file, the application writes to standard output the name of the file enclosed by square brackets.

PASS.

REQ-A1.1.3
After writing the file name, the application writes the contents of the file with each line prefixed by its corresponding line number, a full colon, and a space.

PASS.

REQ-A1.2.1
For example, if a file with the name sample-input.txt contains these four lines:
This is the first line.
This is the second line.
This is the third line.
This is the fourth line.
...then the application writes the following output if the user specifies sample-input.txt on the command line:
[sample-input.txt]
1: This is the first line.
2: This is the second line.
3: This is the third line.
4: This is the fourth line.

PASS.

REQ-A1.3.1
The application processes command-line arguments in the order specified by the user.

PASS.

REQ-A1.3.2
If the user enters no command-line arguments, the application writes no output for the first part of this assignment.

PASS.

REQ-A1.3.3
If the user specifies two or more files, the application writes a blank line between the output corresponding to each file.

PASS.

REQ-A1.4.1
The application then reads lines of standard input.

PASS.

REQ-A1.4.2
For each line of input, if the user enters exit, the application terminates; otherwise, the application interprets the line as a path to a text file.

PASS.

REQ-A1.4.3
The application creates or recreates this file and writes to it two lines of output, the name of the file and the current date and time.

PASS.

REQ-A1.4.4
The application then closes the file, reopens it for reading, and writes its contents to standard output in the same manner as the files in the first part of this assignment.

PASS.

REQ-A1.5.1
The application writes the following prompt before attempting to read each line from standard input:
Enter a file name or type 'exit' to quit.
-->

PASS.

REQ-A1.5.2
Hint: Be sure to flush standard output after writing the prompt.

PASS.

REQ-A1.6.1
If the application cannot read from standard input, it terminates without displaying an error.

PASS.

REQ-A1.6.2
If any I/O errors occur while reading or writing files, the application writes a message to standard error and then continues to process user input.

PASS.

Sample Execution

$ java ChengJade1 input-1.txt input-2.txt
[input-1.txt]
1: This is line one.
2: This is line two.
3: This is line three.
4: This is line four.
5: This is line five.

[input-2.txt]
1: This is line one.
2: This is line two.
3: This is line three.
4: This is line four.
5: This is line five.
6: This is line six.
7: This is line seven.

Enter a file name or type 'exit' to quit.
--> output-1.txt
[output-1.txt]
1: output-1.txt
2: Sun Feb 12 04:20:56 HST 2012

Enter a file name or type 'exit' to quit.
--> output-2.txt
[output-2.txt]
1: output-2.txt
2: Sun Feb 12 04:20:57 HST 2012

Enter a file name or type 'exit' to quit.
--> exit

$ java ChengJade1 missing.txt
[missing.txt]
missing.txt (The system cannot find the file specified)

Enter a file name or type 'exit' to quit.
--> exit

$ java ChengJade1
Enter a file name or type 'exit' to quit.
--> exit

$ java ChengJade1 .
[.]
. (Access is denied)

Enter a file name or type 'exit' to quit.
--> .
. (Access is denied)

Enter a file name or type 'exit' to quit.
--> exit

$ java ChengJade1 < /dev/null
Enter a file name or type 'exit' to quit.
-->