Java Assignment: Polymorphic Containers and Text processing, homework help
Java Assignment: Polymorphic Containers and Text processing, homework help
This exercise will familiarize you with using polymorphic containers and text processing in Java.
We will use the idea of “form letter processing” to convey these ideas.
Form letters are a way of combining a form letter template (text and placeholders for substitution) with a data collection (say, names and addresses) and some computed variables (such as the date) to create a useful result (say, a personalized business letter).
In this exercise we will create the structures for the template, and show that we can process the template to produce the appropriate results.
In the followup exercise for next week, the data collections and output will use files rather than internal storage.
What to Hand In
Please hand in a listing for each program requested, formatted in an easy-to-read style.
Ensure your name, and the name of the file is available in a comment at the top of the file.
You do not need to submit files from the homework starter files that are unchanged.
Also, ensure that you have a sample of the output from the program.
If your program fails to compile, hand in your error listing as your output.
For electronic submission, “zip” your submission together into a single file, to ensure nothing is missing;
For each question asked, provide one or two sentences summarizing your answer. Please be both complete and succinct.
Problems
- Create and Test a Form Letter
- Start with the homework starter files
. These will give you a good framework for creating your FormLetterTemplate. - Examine the
FormLetterEntryabstract class, and create the two derived classesTextEntryandDataItemEntry. Be sure to implement all the abstract methods in each derived class. - Add fields and methods to the
FormLetterclass. These should include a container for FormLetterEntrys, appropriate constructors, and the methods outlined in the class starter. - Compile and run the
FormLetterHelloprogram. When you have implemented the above, it should compile and run. - Capture the output of your test run for your submission.
- Create a new class called
MyFormLetter, which represents another example of a form letter. It must contain at least oneTextEntryand at least oneDataItemEntry. Compile it, run it, and same the output of your test run for your submission. - Optional: Run the JUnit tests and make them all pass (this might take minor changes to your classes).
You will need to ensure the JUnit libraries are on your classpath.
If you submit this optional part, be sure to capture the output showing the JUnit tests passed and include with your submission.
- Start with the homework starter files
- Question: Describe why these files will not compile as they are. Be specific, and display some confirmation for your description. The answer may be stored in a text file, or incorporated as comments in your code.
Notes
- You can put the sample classes into your NetBeans environment by putting all the files except
FormLetterTest.javainto the source directory, and this remaining file into the test directory. Similar instructions for Eclipse. Or, you can also simply use ant with the providedbuild.xmlfile. - While you could create the
TextEntryandDataItemEntryat the bottom of theFormLetterEntry.java, please instead create them as separate, public classes. - Note that while doing input and output in this framework, you should always use the out instance passed in as a parameter, rather that
System.out. This will ensure that all your output happens properly. - Note that the FormLetter class must store an ordered list of FormLetterEntrys. This is best handled by using one of the Collections classes in the
java.utilpackage. Various methods in yourFormLetterclass will iterate through the collection. For example, aListofFormLetterEntrywould be a reasonable collection, instantiated by, say, aLinkedListorArrayListofFormLetterEntry. Because your ordered list storesFormLetterEntryinstances, it will be able to storeTextEntryobjects andDataItemEntryobjects. - Note that the Properties can contain things that might change for each letter (e.g., name) as well as computable things (e.g., date).
- Your addTextEntry method creates a new
TextEntryusing the provided text and adds it to your list - Your addDataItemEntry method creates a new
DataItemEntryusing the provided name and adds it to your list - Your
doFormLettermethod should first go through each item on your list, and invoke itsdoProcessmethod, providing thePropertiesit needs for substitution. Afterward, it should invokeformLetterString()to place the result on the provided output stream. FormLetterHellois the simplest test program using this set of classes, so try running it first.- You must also be sure not to add extra spaces when printing the templates or
FormLetter, and finally when printing out the template, you must print out DataItemEntrys as <name>. That is, a less-than, the name of the data item, and then a greater-than.
"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.
Discount Code: CIPD30
Click ORDER NOW..


