• Post Reply Bookmark Topic Watch Topic
  • New Topic

Form Letter Continue  RSS feed

 
Carlos Diaz G
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, need quick help on understanding the steps. I have added some code to start step 1 and hopefully everything looks good but on step 2 is where Im getting confused or having a little bit of problem understanding. Any help is appreciated!

Here are the steps!

1. Create a class called FormLetterTemplateFileReader which has the following methods:
A no-parameter constructor, which simply creates a FormLetterTemplateFileReader

A constructor which takes a file name

A setFile method which takes a file name, representing the file to read the FormLetter contents from

A readLine method which returns one line read from the opened (and buffered) file

A getTokens 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 > .

Note that the FormLetterTemplateFileReader 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.

A way to test the class to ensure it works properly (e.g., read a file, and output the resulting tokens). This can be a main method, or can be JUnit tests.

Create a class called FormLetterFile which encapsulates a simple main method (not very different than FormLetterHello in many ways):



Here is the my code I did for Step 1


2. Gets two filenames from the command line or by prompting the user (implement one of the choices)

One filename is for the FormLetter, and one for the Properties.

Creates a new FormLetterFileReader using this filename as a parameter.

Creates a FormLetter instance with the filename as the title

While it can read a line from the FormLetterFileReader:

Break the line into tokens

For each token, if it is a simple string (i.e., doesn't begin with a <, add it as a text entry to the FormLetter.

Otherwise, add it as a data item entry to the FormLetter.

Note that various text methods, such as trimming and substrings will be needed to make this go smoothly.

Load a Properties with the contents of the associated file name.

Invoke the doFormLetter method on the FormLetter.

Here is the started code for step 2, so far that is all I have done. I just have confusing on the steps, maybe just not reading them correctly.

 
Zachary Griggs
Ranch Hand
Posts: 83
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First for part 1:

What do you think this code will do when ran?

Also this code:

Does this follow the instruction for constructor?:
A constructor which takes a file name


This code:

Is messy and difficult to read. It seems necessary since we do need to close the file, but Java actually gives a way to avoid this horrific syntax abuse:

Anything inside the try parentheses will be automatically closed and disposed if there's an exception.



For the second part:
2. Gets two filenames from the command line or by prompting the user (implement one of the choices)

If you want to do it via command line, use the args[] variable. If not, this would involve using a Scanner to ask for user input.
One filename is for the FormLetter, and one for the Properties.

Creates a new FormLetterFileReader using this filename as a parameter.

Creates a FormLetter instance with the filename as the title

The user will enter two file names. These file name should be saved in variables, and then used to create two FormLetterFileReaders and two FormLetters. you should make a constructor that takes a file name, and then instantiate these objects.

After that, it sounds like you need to read the two FormLetterFileReaders, and put the read data into the FormLetters. I don't have the FormLetter class, so I can't give specific advise about how to do this part.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From part 1:
1. Create a class called FormLetterTemplateFileReader which has the following methods:
A no-parameter constructor, which simply creates a FormLetterTemplateFileReader

A constructor which takes a file name


I only see the one constructor (the no-parameter one).

Essentially, work through the list ticking off all the bits you think are done, ensuring they match the description in the requirements.
I can see methods in there that aren't mentioned in the requirements (eg readFile and ManageLines), and I don't see others that are (eg readLine and getTokens).
 
Carlos Diaz G
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both Zachary and Dave, I will go back and look at each piece of the instructions and make sure I fix any errors and un-need code. If I have any other questions I will post.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!