Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q2. [15 marks] Write a method that has the following header: public static void printShuffled (String filename) The method reads a text file, filename, sentence
Q2. [15 marks] 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 use Delimiter ("[.:!?]") 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 (let's say 50 characters). 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. A farmer worked in a vineyard and became rich
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started