Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve been having some trouble trying to figure out how to code this. We are ask

ID: 3632256 • Letter: I

Question

I've been having some trouble trying to figure out how to code this. We are asked to use StringTokenizer to come up with the following.

The output should be something like this:
Filename? kennedy
chars 7381
words 1323
average word length 5.58
a/an 31 frequency 0.023
the 86 frequency 0.065

Here is what I have so far:

import java.io.*;
import java.util.*;
///////////////////////////////////////////////////////////////////////////////
class StringTokenizer
{
//-----------------------------------------------------------------------------
public static void main (String [] args) throws Exception
{
Scanner kb = new Scanner(System.in);
System.out.print("Filename? ");
String filename = kb.nextLine();
Scanner sc = new Scanner(new File(filename));
StringTokenizer st = new StringTokenizer(filename);
int count = 0;
while(sc.hasNext())
{
String line = sc.nextLine();

while(st.hasMoreTokens())
{
String token = st.nextToken();
count++;
}
}
System.out.println("chars " + st.countTokens());
System.out.println("words " + count);
System.out.println("average word length " + count);
System.out.println("a/an " + count + " frequency " + count);
System.out.println("the " + count + " frequency " + count);
}
//-----------------------------------------------------------------------------
} // end class StringTokenizer
//////////////////////////////////////////////////////////////////////////

I know this isn't much, but I'd appreciate any help that can be given.

Explanation / Answer

Did you ever figure out how this code should have looked?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote