This assignment asks you to extend the MemoPad program with an important behavior that MemoPads need: the ability to remember memos between runs. We'll do that by adding two responsibilities to the MemoDatabase interface: loading from a file and saving to a file.
For this assignment, download the starting Java files for the MemoPadApp in the form of the zip file homework03-template.zip. This file contains:
java MemoPadApp // creates a default student database
java MemoPadApp 100 // creates a student database with up to 100 memos
java -jar memopad.jar // same as first example above
java -jar memopad.jar 100 // same as second example above
To this directory, you will need to add your MyMemoDatabase class from Homework 2.
On Lines 8 and 10, MemoPadApp creates instances of a MemoDatabase for the MemoPad. Put your class's name in place of my class's name. If you named your class ArrayBasedMemoDatabase, you don't have to do anything!
This should ensure that your class now implements the extended MemoDatabase interface. Compile and run the program to verify this. Of course, the Save and Load buttons won't do anything yet, but...
This method takes a String argument, the name of the file to write. When the user presses the Save to File button, the MemoPad sends the database a save() message, with the current value of the Key: field as the filename.
You get to decide the format of the data that your MemoDatabase object writes to the file. For example, my program writes key/value pairs to a file in this format: eugene>>wallingford
where each line is in the form "key>>value". The >> characters separate the key from the value. Of course, this means that I shouldn't use the > character in my keys or values, because my database class might confuse it with the delimiters in my file. (If you want to implement a solution that isn't as prone to this problem, great!)
This is just an example. You don't have to use >> as the delimiter of your fields, or even write only one memo per line. Just be sure that your user can use spaces in her keys and values.
You can use the code from Session 4 and Session 5 as a starting point for your code that writes to a file.
Don't forget the new import directives that you'll need to add to your class in order to use the various I/O classes that you need for this task.
Compile the program and run it several times, each time saving a new file of memos. Name your files memos1.dat, memos2.dat, .... This will both enable you to verify that your method works and generate test data for the next task!
Be sure that each file tests something different about your program. For example, it would be useful to have an empty file and at least one file with a large number of memos in it, to test the "boundary conditions" of the program.
This method also takes as an argument the name of a file, taken from the current value of the Key: field. When the user presses the Load from File button, the MemoPad sends the database a load() message.
This method should read records of the same format as the data written to file by the save() method.
You can use the code from Session 4 and Session 5 as a starting point for your code that reads from a file. Keep in mind, though, that you won't need a loop around your messages to the StringTokenizer, because you know exactly how many tokens occur on each line.
Don't forget the new import directives that you'll need to add to your class in order to use the StringTokenizer and the various I/O classes needed for this task.
Compile the program and run it several times. Verify that your program can read each of the data files you created in Task 4. You should also be able to load multiple data files into the same memo pad. (*) Also verify that your program can load and save several times during the same execution.
(*) This is a handy feature for combining memo pads created at different times or on different machines.
By the due date and time, submit the files