You will write two new versions of this assignment. Begin by creating subdirectories in hw07 called serialize and randomaccess. Make copies of the original provided files in each new directory. Then add the files to the repository and commit with an appropriate message.
In this first version of the program you will store the book data in a binary file using Java's built-in serializing capabilities. This is accomplished by implementing the Serializable interface for the Book class and then using the ObjectInputStream and ObjectOutputStream I/O classes.
To convert the data you should first modify the saveBooks method to save the serialized objects under the name booklist.ser. After running the program and verifying that the file was created, you can modify the loadBooks method to read the serialized datafile instead of booklist.txt. Also, you should modify the program so that the data file is re-written immediately after a change is made in memory.
In this second version of the program you will store the book data in a binary, random access file. As with the first version your program should save changes to disk immediately after they are made in memory. However, rather than re-writing the entire file each time, you should keep the file open throughout the program and use the seek() command to update only that portion of the file that needs to be saved. Thus, your file variable will need to be a class-wide variable and the file will need to be opened in ``rw'' mode.
This version will be built on the RandomAccessFile I/O class. You should assume that no title has more than 64 characters and that no author has more than 32 characters. Save this version of your solution in a repository named randomaccess.
In addition to the two versions of the program your repository should include a text file named compare.txt that compares the three approaches (text file, serialized file, random-access file) in terms of file size.
I will grade you work according the following criteria:
|Correctness of serialize||14||pts|
|Correctness of randomaccess||14||pts|
|Java Programming Conventions||2||pts|
|Use of VCS||2||pts|
|Contents of compare.txt||4||pts|