CST8102 – CST8132 Object Oriented Programming (Solution)

$ 20.99
Category:

Description

Exercise 8 – File IO
Steps:
• Create a new project in Eclipse
• Copy the provided wordlist.txt file into the Project folder
• Write a single Class named “Reverser” that performs the requested tasks: Tasks:
• Use a java.util.Scanner to load each word in the wordlist.txt file into an ArrayList<String> o Provide the Scanner a reference to a FileReader
• Report the number of words placed into the ArrayList
• Use the java.util.Collections class to reverse the order of the references in the ArrayList
• Use a java.util.Formatter to write the re-ordered words into a new text file named “reversed.txt” o Provide the Formatter with a reference to a FileWriter o Make sure that each word is placed onto a separate line o Additionally, write code so that Java provides the correct end of line terminator for each line.  Note: No , or allowed!
• Write code to help ensure your program has no resource leaks. Grading (1 point each):
• Program opens file with Scanner?
• Program loads words into ArrayList<String>?
• Program reports number of words loaded into ArrayList<String>?
• Collections class was used to reverse order of references to words in the ArrayList<String>?
• Program writes to a new file using Formatter?
• Program uses Java code to insert correct end of line terminator after each word?
• IOException is caught?
• Scanner and Formatter were closed? Formatter was flushed before closed?
• Student shows original file using text editor?
• Student shows new file using text editor?

Reference / Resources:
Note: wordlist was downloaded from the internet and has no warrantees implied or expressed: John Lawler. (1999). An English Word List. Retrieved from http://www-personal.umich.edu/~jlawler/wordlist.html

Appendix – Sample Program outputs:
Reading in data
Loaded 69903 words from file
Reversing word list
Writing word list

wordlist.txt:
a a-horizon a-ok aardvark aardwolf reversed.txt:
zymurgy zymotic zymosis
zymase zygotic

Reviews

There are no reviews yet.

Be the first to review “CST8102 – CST8132 Object Oriented Programming (Solution)”

Your email address will not be published. Required fields are marked *