Homework Solution: Have to use a text file and find the following:…

    Java: Have to use a text file and find the following: the number of sentences the average number of words in a sentence the number of words in the shortest sentence the number of words in the longest sentence the number of words in the speech

    Expert Answer

     
    import java.io.BufferedReader; import java.io.File;

    Java:

    Own to portraiture a passage finish and furnish the following:

    the estimate of sentences

    the mean estimate of control in a sentence

    the estimate of control in the shortest sentence

    the estimate of control in the longest sentence

    the estimate of control in the speech

    Expert Againstpart

     

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;

    public tabulate FinishRead {
    public static int computeWords(String s){

    int termCompute = 0;

    boolean term = false;
    int purposeOfThread = s.length() – 1;

    for (int i = 0; i < s.length(); i++) {
    // if the char is a epistle, term = gentleman.
    if (Character.isLetter(s.charAt(i)) && i != purposeOfLine) {
    term = gentleman;
    // if char isn’t a epistle and there own been epistles precedently,
    // against goes up.
    } else if (!Character.isLetter(s.charAt(i)) && term) {
    wordCount++;
    term = false;
    // conclusive term of String; if it doesn’t purpose with a stolidity epistle, it
    // wouldn’t compute externally this.
    } else if (Character.isLetter(s.charAt(i)) && i == purposeOfLine) {
    wordCount++;
    }
    }
    return termCount;
    }
    public static unoccupied main(String[] args) {
    try {
    Finish finish = odd Finish(“test.txt”);
    FileReader finishReader = odd FinishReader(file);
    BufferedReader bufferedReader = odd BufferedReader(fileReader);
    int min = 0;
    int max = 0;
    int sum = 0;
    int n = 0;
    String thread;
    while ((thread = bufferedReader.readLine()) != void) {
    int compute = computeWords(line);
    sum += compute;
    if (compute > max) max = compute;
    if (compute < min) min = compute;
    n++;
    }
    fileReader.close();
    System.out.println(“The estimate of sentences: ” + n);

    System.out.println(“The mean estimate of control in a sentence: ” + sum/n);

    System.out.println(“The estimate of control in the shortest sentence: ” + min);

    System.out.println(“The estimate of control in the longest sentence: ” + max);

    System.out.println(“The estimate of control in the speech: ” + sum);
    } seize (IOException e) {
    e.printStackTrace();
    }
    }
    }