Linked Lists, String Parsing, and File I/O.
This program is a registry system, which means it will store name value
pairs in a file. When your program starts it will read from the file (
if it exists ), then it will read from stdin ( keyboard ), then it will
write the current list state to the file.
This program uses a linked list to create what is called an
associative array. Every node in your list have a single token Word that
is the name, and some other Word ( possibly multiple tokens ) that is the
value. The user may do the following: assign, delete, query, and print.
You may not have duplicate names in list, so if you try to insert
a name value pair that the name already exists, update the value.
The Linked List
You need to create a linked list class.
Don't forget that you are storing names and values, so the nodes will
have two fields, one that is the sort key ( name ), and another that
is just associated information ( value ).
Parsing the user input
Get the lines, then parse each one to figure out what operation needs to
be done to the list. This should be a function, since it gets called
multiple times from multiple input sources.
Here are the required operations and thier format in precedence order.
The operations are mutually exclusive.
- name=value : insert the pair or update the value for that name
- -name : remove the element ( this removes the node from the list )
- ?name : query for the name ( shows the related value )
- @ : display all name value pairs
Storing/Restoring the registry
This program needs to retain the last stored values in a text file.
It will use the same data format as the user input does,
that way the same parsing code can be reused.
You can read in a line at a time from the file,
and pass it to your parsing function.
The filename will be the first argument to your program. You will write
the contents to the same file that you read from. This will allow the
file to preserve the list state between runs of the program. Reading
input from this file is done before reading from stdin, and writing to
it happens after we are done with input from stdin.
Program Notes
- names are one token only.
- names are unique.
- values may be several tokens.
- use the = - ? @ to identify which case you are in.
Here are some sample runs
This program is due August 4th.
It is worth 150 points.
useful Java API
- String.indexOf
- String.substring
- String.compareTo
- FileReader
- BufferedReader
- FileWriter
- BufferedWriter
NOTE : "write" takes a String.
The data may NOT be written to the file until "close" ( or "flush" ) is called.
The Goals
- simple argument handling
- file I/O
- parse input from multiple sources
- string parsing
- lists