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
Page 2 of 3
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?
s1.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.6666666666666665
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!
Stylistic Guidelines
1. If you notice you’re performing redundant operations, think
about how you could reduce that.
2. Code must be clean and easy to read, this means correct
indentations, spacing, no placeholder
comments, etc.
Page 3 of 3
Include a comment at the beginning of your program with some basic
information and a description
of the program. The comments in your program should be written in
your own words and not
copied from this document. For example:
// Minh Student // Spring 2050 // Programming Assignment #0
// 06/07/49
// This program allows...
Submission and Grading
Turn in your WordCount.java file electronically from the
Assignments link on the course web
page. Please make sure to use exactly this file name, including
identical capitalization.
Part of your program's score will come from its "external
correctness." External correctness
measures whether the output matches exactly what is expected. (We
are very picky about the
output matching exactly. Every character and space must match.)
Programs that do not compile
will receive no external correctness points.
The rest of your program's score will come from its "internal
correctness." Internal correctness
measures whether your source code follows the stylistic guidelines
specified in this document.
This includes having an adequate comment header and an
understanding of parameters, for loops,
and static methods.
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? s1.txt Tolal lines 5 Tolal words 32 Total chars = 143 word length = 1.16875 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. LxL Total lines = 1 Total words = 3 Total chars = 11 Word length = 3.6666666666666665 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! Stylistic Guidelines 1. If you notice you're performing redundant operations, think about how you could reduce that. 2. Code must be clean and easy to read, this means correct indentations, spacing, no placeholder comments, etc. Page 2 of 3
Include a comment at the beginning of your program with some basic information and a description of the program. The comments in your program should be written in your own words and not copied from this document. For example: { Minh Student. 17 Spring 2050 // Programming Assignment #0 // 06/07/19 // This program allows... Submission and Grading Turn in your WordCount.java ſile electronically from the Assignments link on the course web page. Please make sure to use exactly this file name, including identical capitalization. Part of your program's score will come from its "external correctness." External correctness measures whether the output matches exactly what is expected. (We are very picky about the output matching exactly. Every character and space must match.) Programs that do not compile will receive no external correctness points. The rest of your program's score will come from its "internal correctness." Internal correctness measures whether your source code follows the stylistic guidelines specified in this document. This includes having an adequate comment header and an understanding of parameters, for loops, and static methods.
This assignment will give you practice with file processing and using the File and Scanner object. You are going to writ
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
This assignment will give you practice with file processing and using the File and Scanner object. You are going to writ
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!