Complete the following file:

Counter.java

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Counter { private File inputFile; public Counter(File inputFile) { this.inputFile = inputFile; } public int countLines() { int count = 0; /*** complete this method ***/ return count; } public int countWords() { int count = 0; /*** complete this method ***/ return count; } public int countChars(CharacterStats stats) { int count = 0; /*** complete this method ***/ return count; } }

Use the following files:

CharacterStats.java

public class CharacterStats
{
    private int digitCount = 0;
    private int lowerCount = 0;
    private int upperCount = 0;
    private int whiteCount = 0;
    private int otherCount = 0;
    
    public int getDigitCount() { return digitCount; }
    public int getLowerCount() { return lowerCount; }
    public int getUpperCount() { return upperCount; }
    public int getWhiteCount() { return whiteCount; }
    public int getOtherCount() { return otherCount; }
    
    public void incDigit() { digitCount++; }
    public void incLower() { lowerCount++; }
    public void incUpper() { upperCount++; }
    public void incWhite() { whiteCount++; }
    public void incOther() { otherCount++; }
}

CounterTester.java

import java.io.File;

public class CounterTester
{
    public static void main(String args[])
    {
        File inputFile = new File("GettysburgAddress.txt");
        Counter counter = new Counter(inputFile);
        
        int lineCount = counter.countLines();
        System.out.println("Line count: " + lineCount);
        System.out.println("Expected: 25");
        
        int wordCount = counter.countWords();
        System.out.println("Word count: " + wordCount);
        System.out.println("Expected: 267");
        
        CharacterStats stats = new CharacterStats();
        
        int charCount = counter.countChars(stats);
        System.out.println("Character count: " + charCount);
        System.out.println("Expected: 1459");
        
        double digitsPct = stats.getDigitCount()*100.0/charCount;
        System.out.printf("%% Digits: %5.2f%%\n", digitsPct);
        System.out.println("Expected: 0.00%");
        
        double lowerPct = stats.getLowerCount()*100.0/charCount;
        System.out.printf("%% Lower case letters: %5.2f%%\n", lowerPct);
        System.out.println("Expected: 78.00%");
        
        double upperPct = stats.getUpperCount()*100.0/charCount;
        System.out.printf("%% Upper case letters: %5.2f%%\n", upperPct);
        System.out.println("Expected: 0.75%");
        
        double whitePct = stats.getWhiteCount()*100.0/charCount;
        System.out.printf("%% White space characters: %5.2f%%\n", whitePct);
        System.out.println("Expected: 18.44%");
        
        double otherPct = stats.getOtherCount()*100.0/charCount;
        System.out.printf("%% Other characters: %5.2f%%\n", otherPct);
        System.out.println("Expected: 2.81%");
    }
}