Programming Assignment 1
File I/O, Console I/O, and Command-Line Arguments
Code Review for XXX XXX
Build Results
Javadoc: Missing comment for public declaration
csci2912week1.java; line 23Javadoc: Missing comment for public declaration
csci2912week1.java; line 25
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.
FAIL. File was submitted as csci2912week1.java
.
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.
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.
PASS.
FAIL. The implementation contains no JavaDoc.
FAIL. The application does not process command-line arguments.
PASS.
FAIL. If more than one file is specified, the application displays the wrong line numbers. The counter1
variable should be reset within the for
loop.
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.
FAIL. The application does not process command-line arguments.
FAIL. The application does not process command-line arguments.
FAIL. The application asks the user to enter the name of a file (or files) to open.
FAIL. The application does not write a blank line between the output corresponding to each file.
PASS.
exit
, the application terminates; otherwise, the application interprets the line as a path to a text file.PASS.
FAIL. The application also writes to the file a line number.
FAIL. The application does not open the file after creating it.
Enter a file name or type 'exit' to quit. -->
PASS.
FAIL. The application does not flush standard output after writing the prompt.
FAIL. The application crashes if standard input is closed.
PASS.
General Observations
Note these observations will not affect the grade.
Writing a method to display the contents of a file would simplify the implementation.
The application does not correctly parse input files with names that contain spaces.
To print the current date and time, it would have been simpler to use the
Date
class, which was discussed briefly in class and the relevant API was linked twice from the homework assignment.The implementation is more complex that it needs to be. Please see the example implementation.
Avoid calling
System.exit
if possible. Calling this method abruptly terminates the JVM and is unsafe to execute in certain contexts. Consider this:public class Program { public static void main(String[] args) { try { System.out.println("Calling System.exit()..."); System.exit(0); // This will not execute. System.out.println("System.exit() returned."); } finally { // Warning: This will not execute, either! System.out.println("Final block executing..."); } } }
Sample Execution
$ java csci2912week1 input-1.txt input-2.txt Enter filenames, seperated by a space: 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] 6: This is line one. 7: This is line two. 8: This is line three. 9: This is line four. 10: This is line five. 11: This is line six. 12: This is line seven. Enter a file name or type 'exit' to quit. -->output-1.txt [output-1.txt] 1: output-1.txt 2: Sat Feb 11 22:22:13 HST 2012 Enter a file name or type 'exit' to quit. -->output-2.txt [output-2.txt] 1: output-2.txt 2: Sat Feb 11 22:22:13 HST 2012 Enter a file name or type 'exit' to quit. -->exit $ java csci2912week1 Enter filenames, seperated by a space: "input 3.txt" ["input] "input (The system cannot find the file specified) Enter a file name or type 'exit' to quit. -->exit $ java csci2912week1 < /dev/null Enter filenames, seperated by a space: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at csci2912week1.main(csci2912week1.java:39) $ java csci2912week1 Enter filenames, seperated by a space: missing.txt [missing.txt] missing.txt (The system cannot find the file specified) Enter a file name or type 'exit' to quit. -->. [.] 1: . 2: Sat Feb 11 22:30:43 HST 2012IO Exception Enter a file name or type 'exit' to quit. --> [] 1: 2: Sat Feb 11 22:30:43 HST 2012IO Exception Enter a file name or type 'exit' to quit. -->exit