public class MessageBuilder
{
    // for testing
    // includes first word (so calls can be checked)
    static String[] wordsForTesting;
    static int currentWordIndex;
    
    // package access for testing
    String message;
    int numWords;
    
    // for testing
    public MessageBuilder()
    {
        message = null;
        numWords = -1;
    }
    
    public MessageBuilder(String startingWord)
    {
        message = startingWord;
        numWords = 1;
        
        String nextWord = getNextWord(startingWord);
        
        while(nextWord != null)
        {
            message += " " + nextWord;
            numWords++;
            nextWord = getNextWord(nextWord);
        }
    }
    
    public String getNextWord(String s)
    {
        if( ! s.equals(wordsForTesting[currentWordIndex]) )
            throw new IllegalStateException("getNextWord called with wrong word");
        
        if(currentWordIndex < wordsForTesting.length - 1)
        {
            currentWordIndex++;
            return wordsForTesting[currentWordIndex];
        }
        else
        {
            return null;
        }
    }
    
    public String getAbbreviation()
    {
        String abbreviation = "";
        
        for(String word : message.split(" "))
            abbreviation += word.substring(0, 1);
        
        return abbreviation;
    }
}
