FormLetterFileReader which has the following methods:
FormLetterFileReader setFile method which takes a file name, representing the file to read the FormLetter contents fromreadLine method which returns one line read from the opened (and buffered) filegetTokens method which returns an array of tokens found on the line. A token is either a buffer of text, or a replacement data item. These data items are recognized by starting with a { and ending with a } .
FormLetterFileReader may store the array differently, internally; but it needs to return the result as an array of Strings. The Strings will be tokenized and constructed into a FormLetter by the FormLetterFile.main method, or can be JUnit tests.FormLetterFile which encapsulates a simple main method (not very different than FormLetterHello in many ways):
FormLetter, and one for the Properties.FormLetterFileReader using this filename as a parameter.FormLetter instance with the filename as the title
Properties with the contents of the associated file name.doFormLetter method on the FormLetter.FormLetterFile main method and capture the result for your submission.FormLetter template file and associated Properties file, and test your program by running FormLetterFile with them.setFile. Calling readLine without opening the file first should throw an appropriate exception getTokens should simply return a zero-length array of Strings if called with an empty StringsetFile method needs to arrange for the file to be read one line at a time. This will make it convenient for the input to be setup as a BufferedReader object. A BufferedReader requires a FileReader to construct it. A FileReader is constructed from a File Also, note that it is possible the file does not exist, or perhaps cannot be read. Thus, your setFile may want to call a setInput function like so:
private void setInput(String filename) throws FileNotFoundException {_x000D_
try {_x000D_
FileReader f = new FileReader(filename);_x000D_
input = new BufferedReader(f); // Assumes input is the field name for the BufferedReader_x000D_
} catch (FileNotFoundException fnfe) {_x000D_
System.err.println("File "+file+" not found");_x000D_
throw fnfe; // rethrow the exception_x000D_
}_x000D_
}_x000D_
readLine method can use delegation return input.readLine(), just like any other BufferedReader. However, you may also need to catch a possible IOException it may raise.StringTokenizer provides another very flexible way to parse input strings.
DataItemEntry name.hasMoreTokens(), which returns true when there is another token to read, and nextToken(delimiter), which returns the next String bounded by that delimiter.StringTokenizer, you may provide the default token delimiter, and a boolean indicating whether you’d like to get the delimiters themselves back as tokens.String indexOf and substring methods.Scanner classList<String>, since it is easy to add Strings to it. A LinkedList of String is a good implementation class. To turn a List into an array, remember to use the toArray method of the collection object, and pass a new String[0] as a parameter to coerce the return type.Properties can be loaded directly, given a file name. _x000D_
{date}_x000D_
Dear {name},_x000D_
_x000D_
BREAKING: {newsHeadline}_x000D_
_x000D_
This is an ALL HANDS ON DECK SITUATION:_x000D_
If we don't fight back, the {otherParty} will get their way._x000D_
_x000D_
Donate to {thisParty} TODAY so we can finally put an end to the {otherParty} shenanigans!_x000D_
_x000D_
Give {amount}£ now_x000D_
_x000D_
Or, donate another amount_x000D_
_x000D_
Paid for by the {thisParty} PAC, not authorized by any candidate or candidate's committee._x000D_
_x000D_
name=Loyal Party Supporter_x000D_ newsHeadline=Rt. Hon. Lord North calls for OUTRAGEOUS INCREASE IN TAXES on TEA!_x000D_ thisParty=Sons Of Liberty_x000D_ otherParty=British_x000D_ date=May 8, 1773_x000D_ amount=1_x000D_

WhatsApp us