Page 1 of 1

In Java

Posted: Fri May 20, 2022 3:19 pm
by answerhappygod
In Java
In Java 1
In Java 1 (102.09 KiB) Viewed 34 times
In Java 2
In Java 2 (64.97 KiB) Viewed 34 times
This assignment will give you practice with file processing and using the File and Scanner object. You are going to write a program that allows the user to enter a file name, which then allows the program to analyze the file and print out file statistics. Your program is required to exactly reproduce the format and behavior of the log of execution at the end of this write-up, so you may want to look that over first. At a minimum, your program should have the following static methods in addition to method main: a method to give the program overview/intro • a method that examines the file You may define more methods than this if you find it helpful. You can assume the file a user enters will always be a text file. You will notice at the end of the log that you are to report various statistics about the content from the input file. You are to report: 1. Total lines 2. Total words 3. Total chars 4. Average word length Here are a few helpful hints to keep in mind. • Use File and Scanner object to help with getting user input and file input • Use the example text file to check if your program outputs the same analysis Reminder you shouldn't have all of the code in main because you are required to have the methods described at the beginning of this write-up. We will once again expect you to use good programming style and to include useful comments throughout your program. We will expect you to make appropriate choices about when to store values as int versus double, which if else contstructs to use, what parameters to pass, and so on. Your program should be stored in a file called Wordcount.java

Log of execution (user input underlined) Example 1: This program asks a user for a file and reports the following statistics: total lines, total words, total characters, and average word length. What file do you want me to examine? 31.txt Total lines = 5 Total words = 32 Total chars = 143 Word length = 4.46875 Example 2: This program asks a user for a file and reports the following statistics: total lines, total words, total characters, and average word length. What file do you want me to examine? smallExample.txt Total lines = 1 Total words = 3 Total chars = 11 Word length = 3.666666666 s1.txt (This is a sample text file you can use to see if your stats match up) Neo : What? on the computer, now appears 'The Matrix has you...' Neo : What the hell? On the computer, now appears 'Follow the white rabbit...' Neo : Follow the white rabbit? smallExample.txt (This is a sample text file you can use to see if your stats match up) oh hello you!