The goal of this lab is to practice working with Java file I/O by
adding load/save functionality to the Document
class you
completed in a previous lab.
Since we will be working with a command-line Java application, you should not use Eclipse for this lab. You can edit the Java files using the gedit text editor and compile your code in the terminal. The Web-CAT submission tests for this lab won't run Checkstyle, so you don't need to worry about low-level formatting issues.
As a reminder, you can follow the following steps to compile and execute a Java program in the terminal:
$ cd the_directory_where_your_code_is_stored $ javac File1.java File2.java ... $ java File1
This example assumes that File1.java
contains the
main method for the application.
The following unfinished files are provided:
Document.java
Editor.java
This is an
editor application that provides a command-line interface to
the Document
class.
Download the files above and complete Document.java
so that the unfinished methods conform to the Javadoc comments. Test
your completed file by running the provided application program.
The current implementation of the Editor
class does not
include code for handling exceptions related to file I/O: If you
attempt to open a non-existent file, or to write a file to a location
where do not have permission, the application will crash.
Modify Editor.java
by removing
all throws
declarations and adding try/catch blocks
to saveFile
and loadFile
. If an exception
occurs, these methods should print a helpful error message and
then allow execution to proceed normally.
Submit your completed version of Document.java
through
Web-CAT. Style checking is turned off, and you have an unlimited
number of submissions. If you have trouble with your submission, you
may find it helpful to look at the JUnit submission tests:
DocumentTestWithIO.java
.