CISS-110 Project 4
This project deals with EOF-based loops, using the while construct, where we do not know the exact number of times a loop will iterate (perform the associated block of code). We will continue to build on our knowledge of if/else constructs and introduce the idea of nested loops.
Learning outcomes
- Implementing EOF loops.
- Working with files.
- Using
Scannerwith files. - Using
Scannerwith strings. - Using
StringBuilderand theappend()method. - Confirmation program produces desired results.
You will work with two files:
Scanner inFile = new Scanner(new FileReader("input.txt"));
PrintWriter outFile = new PrintWriter("output.txt");
For each version of the project, use the following text as provided:
A frosted glass plate rested amidst the bottles, glasses, cups, and saucers upon the table. For so many dishes, they held practically no food, save one plate. The plate was made of ordinary green glass and was likely kept in the refrigerated unit of the Garde Manger station beyond the swaying hinged door, well within the realm of the kitchen. The contents of the plate: a variety of leafy greens, sliced radish, carrot, celery, pepperoncini, and pickled beets. This plate and its colorful bounty were now on display at the table for all to see. In fact, the only form of true sustenance at this table was upon this plate. "That's a very colorful salad you have there, Michael," said Shannon. She was seated to Michael's right at the table of five who were gathered around the six-top. Shannon was petite, but strong, with long, curly auburn hair and pale, freckled skin. "Yes, Michael. Very artistic choice this fine Saturday night," quipped Peter, and he gave a genuine, jovial smile. Peter was seated on Michael's left, dressed in a business suit, clean cut with slightly obvious chiseled features. Jason sat on the opposite side of Peter. He scowled and offered, "That's a rather lame dinner, if you ask me." "Which I didn't," answered Michael and added, "but your stunning choice of liquid entree has not gone unnoticed." Jason raised his glass of single-malt scotch and announced, "Alcohol! Because no great story ever started with someone eating a salad."
Contents of input.txt.
You have two choices for this project:
- You will read lines from the file. With each line you will:
- Get each word from the line.
- Upcase the entire word.
- Reverse the word using a simple
forloop. (PAPER becomes REPAP). You are NOT allowed to usereverse(). - Write each reversed word to the output file on its own line.
- Report to the user the total number of lines from the original file.
- Report to the user the total number of words written.
Sample file content (abbreviated):
A DETSORF SSALG ETALP DETSER TSDIMA EHT ,SELTTOB ,SESSALG SPUC DNA SRECUAS NOPU EHT .ELBAT ROF OS YNAM ,SEHSID YEHT DLEH YLLACITCARP ...
Your output (if using the sample data) will look like:
Total lines read: 13 Total words written: 248
Submit the project to the Learning Management System as Project4_lastname.java.