Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method that has the following header: public static void printShuffled(S

ID: 3848138 • Letter: W

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 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. 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.

Explanation / Answer


import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Sam
*/
public class SentenceDetector {
    public static void printSuffle(String fileName){
        ArrayList<String> aList;
        try{
            File file = new File(fileName);
            file.length();
            aList = new ArrayList<>((int)(file.length()/50));
            Scanner sc = new Scanner(file);
            sc.useDelimiter("[.:!?]");
            while (sc.hasNext()){
                aList.add(sc.next());
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(SentenceDetector.class.getName()).log(Level.SEVERE, null, ex);
            return;
        }

        Collections.shuffle(aList);
        for (String s:aList)
            System.out.print(s+".");
        System.out.println("");
    }
    public static void main(String[] args) {
        printSuffle(FILE NAME HERE);
    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote