CS 160, Fall 2013
Programming Assignment P5
File Statistics

Programming due Monday, Nov. 11 at noon; late deadline Nov. 11 at 10 p.m.


A Program to Gather File Statistics

This programming assignment has five objectives:
  1. to practice file input using a Scanner,
  2. to practice file output using a PrintWriter,
  3. to define and use class variables,
  4. to write methods that take arrays as parameters,
  5. and to use the Character wrapper class.

Description

The program takes the name of an input and output file on the command line. It reads the input file into an array of strings, then gathers file statistics on the contents of the file, and finally writes the statistics out to another file.

Instructions

For this assignment, you must follow directions exactly. Create a P5 project in Eclipse then write a class P5 with the following components:
  1. Declare an array of type String as a class (static) variable and allocate 100 entries.
  2. Declare the following integers as class (static) variables: numberLines, numberWords, numberChars, numberUpper, numberLower, numberDigits, numSpaces, numberTabs, numberSpecial, and initialize all of them to zero.
  3. Write a main program as follows:
  4. All methods are static and private, and have no return values.
  5. Implement readFile to open the specified file and read all its lines into to the String array class variable.
  6. The readFile method should also correctly set the numberLines variable to the number of lines read.
  7. Implement gatherStatistics with one parameter which is an array of Strings.
  8. Implement an outer loop in gatherStatistics to iterate the String array so you can examine each line.
  9. Figure out the number of characters in the line, and add it to numberChars.
  10. Figure out the number of words in the line, and add it to numberWords.
  11. Note: The StringTokenizer class may be especially useful for this, we will discuss it in class.
  12. Implement an inner loop in gatherStatistics to iterate each character in the current line.
  13. To this inner loop, add code to analyze each character, updating the associated counts:
  14. Note: The Character wrapper class may be especially useful for this, we will discuss it in class.
  15. Implement writeFile to open the specified file and write the file statistics as shown below.
  16. The example below shows the correct output for the Declaration.txt, which you should use as the test input file.
Number of Lines: 42
Number of Words: 1335
Number of Characters: 8113
Number of Uppercase: 231
Number of Lowercase: 6374
Number of Digits: 5
Number of Spaces: 1305
Number of Tabs: 26
Number of Special: 172

Specifications

Your program must meet the following specifications:

Grading Criteria

Submit your program to the Checkin tab on the course website, as you were shown in the recitation, and read the syllabus for the late policy (if necessary).

© 2013 CS160 Colorado State University. All Rights Reserved.