import java.util.*;

/**
 * A very simple Document class that can be used to explore
 * issues related to accessibility/visibility
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Document
{
    // Note that the attributes are private
    private String       delimiters, text;


    /**
     * Explicit Value Constuctor
     *
     * @param text   The text of the document
     */
    public Document(String text)
    {
		this.text = text;
		delimiters = " ,.;:!?\t\n\r";
    }


    /**
     * Append additional text to the end of this Document
     *
     * @param addition   The text to append
     */
    public void append(String addition)
    {
		text = text + addition;
    }


    /**
     * Get the characters used to delimit words
     *
     * Note: This method is public but there is no reason
     *       for non-child classes to have access
     *
     * @return  A String containing the delimiters
     */
    public String getDelimiters()
    {
		return delimiters;
    }


    /**
     * Get a description of this Document that
     * includes a statistical summary
     *
     * @return  The description
     */
    public String getDescription()
    {
		String       result;

		result = "Contains " + getWordCount() + " word(s).";

		return result;
    }


    /**
     * Get the text of this Document
     *
     * @return  The text
     */
    public String getText()
    {
		return text;
    }



    /**
     * Get the number of words in this Document
     *
     * @return  The number of words
     */
    public int getWordCount()
    {
		int count;
		StringTokenizer tokenizer;

		tokenizer = new StringTokenizer(text, delimiters);
	
		count = tokenizer.countTokens();

		return count;
    }

}
