FileAnalyzer.java
import java.io.FileNotFoundException;
import java.io.File;
import java.util.Scanner;
/**
This class prints a report on the contents of a number of files.
*/
public class FileAnalyzer
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
FileCounter counter = new FileCounter();
boolean done = false;
while (!done)
{
. . .
counter.read(. . .);
. . .
}
System.out.println("Characters: " + counter.getCharacterCount());
System.out.println("Words: " + counter.getWordCount());
System.out.println("Lines: " + counter.getLineCount());
}
}
FileCounter.java
/**
A class to count the number of characters, words, and lines in files.
*/
public class FileCounter
{
. . .
/**
Construct a FileCounter object.
*/
public FileCounter()
{
. . .
}
/**
Processes an input source and adds its character, word, and line
counts to this counter.
@param in the scanner to process
*/
public void read(Scanner in)
{
. . .
}
/**
Gets the number of words in this counter.
@return the number of words
*/
public int getWordCount()
{
. . .
}
/**
Gets the number of lines in this counter.
@return the number of lines
*/
public int getLineCount()
{
. . .
}
/**
Gets the number of characters in this counter.
@return the number of characters
*/
public int getCharacterCount()
{
. . .
}
}