Question: Write a method that has the following header: public static void printShuffled(String filename) The method reads a text file, filename, sentence by sentence into an
Write a method that has the following header:
public static void printShuffled(String filename)
The method reads a text file, filename, sentence by sentence into an array list, shuffles the sentences, and then prints out the shuffled contents. Assume sentences end with one of these characters: ".", ":", "!" and "?". Your method should create an array list for storing the sentences. The array list should be created with approximately the correct number of sentences, instead of being gradually expanded as the file is read in.
Write a test program that reads the attached story.txt file and prints its contents using your method.
Hints:
To read sentences instead of lines or words, use the method useDelimiter("[.:!?]")of the Scanner class.
To determine the approximate number of sentences, divide the file length, representing the size of the file, by an assumed average size of a sentence (lets say 50 characters).
story.txt
A farmer worked in a vineyard and became rich. He wanted his sons to be just like him. On his deathbed, the farmer told his sons that there was a great treasure buried in the vineyard. After the farmer died, the sons went to the vineyard and dug up the soil. They could not find a buried treasure! At harvest time, the vineyard produced the best grapes ever. Now, the sons understood the meaning of the treasure.
Sample Output
Now, the sons understood the meaning of the treasure. On his deathbed, the farmer told his sons that there was a great treasure buried in the vineyard. He wanted his sons to be just like him. They could not find a buried treasure. At harvest time, the vineyard produced the best grapes ever. After the farmer died, the sons went to the vineyard and dug up the soil. The farmer worked in a vineyard and became rich.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
