Class Sentence

java.lang.Object
  |
  +--Sentence

public class Sentence
extends Object

The Sentence class represents a single sentence. A sentence is considered to be any String ending in a '.', ':', ';', '?', or '!'. Thus, in this context a Sentence object may contain strings that do not represent gramatically correct English sentences.

Methods are provided to count the number of words that appear in the sentence, and to get the next word from the sentence.


Constructor Summary
Sentence(String s)
          Construct a new Sentence based on the parameter s.
 
Method Summary
 int countWords()
          Count the number of words in this Sentence.
 Word nextWord()
          Get the next word in this Sentence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sentence

public Sentence(String s)
Construct a new Sentence based on the parameter s. Assume that any string passed to this constructor represents a valid sentence.

Parameters:
s - a String representing a sentence.
Method Detail

countWords

public int countWords()
Count the number of words in this Sentence. Words are considered to be any elements of the Sentence that are separated by spaces, tabs or new lines.

Returns:
the number of words in this Sentence.

nextWord

public Word nextWord()
Get the next word in this Sentence. If there are no more words in this Sentence the value null will be returned. Any punctuation appearing at the end of a word will not appear in the Word object that is returned. For example, the the second word in the Sentence:
"For example, this is a test."
will be "example" and not "example,". Similarly, the final word in that sentence will be "test" and not "test.".

Returns:
the next word in this Sentence or null if there are no more words.