/*
  Chris Poon
  Burnett Honors College Summer Institute

  StringTokenizer Example.

  This program is to illustrate the use of the StringTokenizer in Java.
  As there is no need for complex object interaction, everything has been written
   in main.
  
  The program reads data from an input file, "in.txt".
  The first line of the file shall contain an integer, n.
  The next n lines will contain sentences of at least one word.

  The program's goal is to read these lines, output the number of words in each
   sentence as well as the number of words in that sentence with less than 4 letters.

*/

import java.io.*;
import java.lang.Math;
import java.util.StringTokenizer;

public class TokenExample 
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader input=new BufferedReader(new FileReader("in.txt"));
		String aline;
		String aword;
		int num, wordCount, smallCount;
		StringTokenizer strtok;			//Our StringTokenizer (not yet instanciated)

		aline=input.readLine();			//Reads the initial integer, n, in the file
		num=Integer.parseInt(aline);	// and stores into num.

		for (int x=0;x<num;x++){		//Loop to read the next n lines.
			aline=input.readLine();
			wordCount=0;
			smallCount=0;

			strtok=new StringTokenizer(aline);	//the instanciation!!
												// parameter is the string to tokenize.
												// Other useful constructors exist.

			while (strtok.hasMoreTokens()){		//a loop that tokenizes the string
												// and stores each token/word
												// into _aword_ for analysis.
				aword=strtok.nextToken();
				wordCount++;
				if (aword.length()<4) smallCount++;
			}

			//below is the desired output statement describing number of words/tokens
			//  and how many have less than 4 letters.
			System.out.println("Sentence " + (x+1) + " has " + wordCount + " words, " + smallCount+ " of which have less than 4 letters.");
		}
	}
}


/*  example "in.txt"
3
Burnett Honors College is the best!
Go UCF!!!Our Programming Team Rox0rs!!!Yea!
Warp Speed,Mr Sulu.

----output----
Sentence 1 has 6 words, 2 of which have less than 4 letters.
Sentence 2 has 5 words, 1 of which have less than 4 letters.
Sentence 3 has 3 words, 0 of which have less than 4 letters.

--------------
How can we modify to delimit exclamations points and commas?
*/