import javabook.*;

/*
 * Introduction to OOP with Java 2nd Edition, McGraw-Hill
 *	
 *   Extract the words in a given sentence and
 *   print them using one line per word. 
 *  
 * @author Dr. Caffeine
 *
 */
class CountJava
{
    public static void main (String[] args)
    {
        MainWindow  mainWindow;
        OutputBox 	outputBox;
        InputBox    inputBox;
        
        mainWindow  = new MainWindow("Extract Words");
        outputBox   = new OutputBox( mainWindow );
        inputBox    = new InputBox( mainWindow );
                
        mainWindow.setVisible( true ); 
        outputBox.setVisible( true );
        
        int       index,    numberOfCharacters,
                  beginIdx, endIdx; 
      
        String    word, 
                  sentence = inputBox.getString();

        numberOfCharacters = sentence.length();
        index = 0;
        
        while ( index < numberOfCharacters ) {
        
            //ignore leading blank spaces
            while (index < numberOfCharacters && 
                   sentence.charAt(index) == ' ') {
                
                index++;
            }
          
            beginIdx = index;
          
            //now locate the end of the word
            while (index < numberOfCharacters && 
                    sentence.charAt(index) != ' ') {
              
                index++;
            }
          
            endIdx = index;
            
            //outputBox.printLine( beginIdx + "      " + endIdx );  //TEMP
          
            if (beginIdx != endIdx) {
              
              //another word is found, extract it from the 
              //sentence and print it out
              
                word = sentence.substring( beginIdx, endIdx );
                
                outputBox.printLine( word  );
            }
        }
                    
    }
    
}