Java Lab #9: File I/O

In this lab you will enhance Clacky again so that it can save the registers created last time as files. This gives the program two important new abilities. First it can use a huge number of registers. Second the values in the registers will persist between invocations of the program. This lab gives you some practice creating using files. The starting point for this lab is the Clacky v1.1 code in Lab #8.

Proceed as follows

  1. Add a file containing interface Storage as discussed in class. You can use the version on GitHub.

  2. Modify InMemoryStorage so that it properly implements the Storage interface.

  3. Create a class OnDiskStorage that implements the Storage interface using a separate file for every register. For example the value stored in register 5 should be in the file "5.reg." Store the string version of the rational numbers in the files so you can view them (or even edit them) in a plain text editor like Notepad if you wish.

    There are a few tricky issues with making these changes, particularly with respect to exception handling. See my lecture of 2014-11-13 for more information.

  4. Modify the Clacky main program to create an object of type OnDiskStorage instead of InMemoryStorage. You shouldn't have to modify any other part of the main program.

As a final optional step, consider exporting your program to an executable jar file as I demonstrated in the lecture. This would allow you to use Clacky outside of Eclipse and makes the program much more practical. Turn in your final program with appropriate comments. I'm mostly interested in just the Storage.java and OnDiskStorage.java files. Be sure your name is on your submission.

Enjoy!