import java.io.*;
import java.util.*;

/**
 * StringTokenizerExample
 *
 * @author Michael Norton
 * @version 26 August 2002
 *
 * Modifications: None
 *
 * Acknowledgements: None
 */
public class StringTokenizerExample
{
	//---------------------------------------------------------------------
	// Declarations
	//---------------------------------------------------------------------
	private String sentence;

	/**
	 * Constructor: StringTokenizerExample - gets a sentence and prints out
	 * the sentence
	 *
	 * @throws IOException
	 */
	public StringTokenizerExample() throws IOException
	{
		getSentence();
		printResults();

	} // constructor


	/**
	 * getSentence - prints a prompt and sets the value of sentence
	 *
	 * @throws IOException
	 */
	public void getSentence() throws IOException
	{
		System.out.print("Please enter a sentence: ");

		sentence = readString();

	} // method getSentence


	/**
	 * printResults - counts the tokens of sentence using a loop and
	 * compares this to the countTokens() method of the StringTokenizer
	 */
	{
		StringTokenizer token = new StringTokenizer(sentence);

		int counter = 0;
		int numTokens = token.countTokens();

		while(token.hasMoreTokens())
		{
			token.nextToken();
			counter++;

		} // end while

		if(numTokens == counter)
			System.out.println("\nI got the same answer as the tokenizer!");
		else
			System.out.println("\nWe disagree. (Someone screwed up!!!!");

	} // method printResults

	/****************************** private methods *************************/


	/**
	 * readString - this method gets input from the user and returns it to
	 * the calling method
	 *
	 * @return String
	 * @throws IOException
	 */
	private String readString() throws IOException
	{
		BufferedReader reader = new BufferedReader(new InputStreamReader
			(System.in));

		return reader.readLine();

	} // method readString

	/******************************* static methods *************************/

	//---------------------------------------------------------------------
	// main
	//
	// "ignition" for the class - Here we create an instance of ourself and
	// invoke the appropriate methods via the constructor of the object
	//----------------------------------------------------------------------
	public static void main(String[] args) throws IOException
	{
		new StringTokenizerExample();


	} // method main

} // class StringTokenizerExample
