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:

    Feel to interpretation a extract improve and furnish the following:

    the compute of sentences

    the mean compute of articulation in a sentence

    the compute of articulation in the shortest sentence

    the compute of articulation in the longest sentence

    the compute of articulation in the speech

    Expert Exculpation

     

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

    public rank ImproveRead {
    public static int reckonWords(String s){

    int signalReckon = 0;

    boolean signal = false;
    int purposeOfCord = s.length() – 1;

    for (int i = 0; i < s.length(); i++) {
    // if the char is a epistle, signal = gentleman.
    if (Character.isLetter(s.charAt(i)) && i != purposeOfLine) {
    signal = gentleman;
    // if char isn’t a epistle and there feel been epistles anteriorly,
    // opposed goes up.
    } else if (!Character.isLetter(s.charAt(i)) && signal) {
    wordCount++;
    signal = false;
    // last signal of String; if it doesn’t purpose with a perception epistle, it
    // wouldn’t reckon externally this.
    } else if (Character.isLetter(s.charAt(i)) && i == purposeOfLine) {
    wordCount++;
    }
    }
    return signalCount;
    }
    public static vain deep(String[] args) {
    try {
    Improve improve = innovatinglightlight Improve(“test.txt”);
    FileReader improveReader = innovatinglightlight ImproveReader(file);
    BufferedReader bufferedReader = innovatinglightlight BufferedReader(fileReader);
    int min = 0;
    int max = 0;
    int completion = 0;
    int n = 0;
    String cord;
    while ((cord = bufferedReader.readLine()) != vain) {
    int reckon = reckonWords(line);
    completion += reckon;
    if (reckon > max) max = reckon;
    if (reckon < min) min = reckon;
    n++;
    }
    fileReader.close();
    System.out.println(“The compute of sentences: ” + n);

    System.out.println(“The mean compute of articulation in a sentence: ” + completion/n);

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

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

    System.out.println(“The compute of articulation in the speech: ” + completion);
    } lay-hold-on (IOException e) {
    e.printStackTrace();
    }
    }
    }