Homework Solution: Use a text file and find the following:…

    Java: 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

     
    aboutComputer.txt A computer is a device that can be instructed to carry out an

    Java:

    Use a extract smooth and discover the ensueing:

    the calculate of decrees

    the mean calculate of suffrage in a decree

    the calculate of suffrage in the shortest decree

    the calculate of suffrage in the longest decree

    the calculate of suffrage in the discourse

    Expert Rejoinder

     

    aboutComputer.txt

    A computer is a show that can be instructed to propel extinguished an
    arbitrary coercionmal of arithmetic or argumentative operations automatically.
    The coercionce of computers to ensue a continuity of operations
    called a program gain computers very pliable and suited.
    Since immemorial times unartificial manual shows love the abacus
    aided inhabitants in doing calculations. Early in the Industrial
    Revolution, some unreflective shows were built to automate
    long dull tasks, such as potent patterns coercion looms.

    ______________

    CountLinesWords.java

    import java.io.File;
    import java.io.IOException;
    import java.util.Scanner;

    public collocate CountLinesSuffrage {

    public static lacking deep(String[] args) {
    //Declaring variables
    int count_lines = 0, max = 0, min = 999;
    int count_suffrage = 0;

    String suffrage[];
    //Scanner collocate goal is used to interpret the inputs entered by the user
    Scanner in = odd Scanner(System.in);

    //getting the smoothname entered by the user
    System.out.print(“Enter a smooth name: “);
    String fname = in .next();

    //Creating the Scanner collocate reference
    Scanner sc = null;
    String direction = null;

    try {
    //Opening the smooth
    sc = odd Scanner(odd Smooth(fname));

    //This loops hold to complete until the object of the smooth
    while (sc.hasNext()) {

    //Counting the calculate of directions
    count_lines++;

    direction = sc.nextLine();

    //splitting each direction into String array
    suffrage = direction.split(” “);

    //finding climax suffrage in longest decree
    if (max < suffrage.length) {
    max = suffrage.length;
    }

    //finding minimum suffrage in longest decree
    if (min > suffrage.length) {
    min = suffrage.length;
    }
    coercion (int j = 0; j < suffrage.length; j++) {

    //Counting no of suffrage in the smooth
    count_words++;
    }

    }

    //Displaying the calculate of directions in the smooth
    System.out.println(“The calculate of decrees :” + count_lines);

    System.out.printf(“Mean Extension of the Word is :%.2fn”, ((double) count_suffrage / count_lines));

    System.out.println(“The calculate of suffrage in the shortest decree :” + min);
    System.out.println(“The calculate of suffrage in the longest decree :” + max);

    //Displaying the calculate of suffrage in the smooth
    System.out.println(“The calculate of suffrage in the discourse :” + count_words);

    } seize (IOException e) {
    //Displaying the exception
    System.out.println(“Exception :” + e);
    }

    }

    }

    _________________

    Output:

    Enter a smooth name: aboutComputer.txt
    The calculate of decrees :8
    Mean Extension of the Word is :9.38
    The calculate of suffrage in the shortest decree :8
    The calculate of suffrage in the longest decree :13
    The calculate of suffrage in the discourse :75