import javabook.*;

/*
 * Introduction to OOP with Java 2nd Edition, McGraw-Hill
 *	
 *   Count the number of times the word 'java' occurs
 *   in input. Case-insensitive comparison is used here.
 *   The program terminates when the word STOP (case-sensitive)
 *   is entered.
 *  
 * @author Dr. Caffeine
 *
 */
class CountJava
{
    public static void main (String[] args)
    {
        MainWindow  mainWindow;
        OutputBox 	outputBox;
        InputBox    inputBox;
        
        mainWindow  = new MainWindow("Count 'Java' Words");
        outputBox   = new OutputBox( mainWindow );
        inputBox    = new InputBox( mainWindow );
                
        mainWindow.setVisible( true ); 
        outputBox.setVisible( true );
        
        int       javaCount  = 0,
                  inputCount = 0;
                  
        boolean   repeat     = true;
        
        String    word;
        
        while ( repeat ) {
        
            word = inputBox.getString("Next word:");
            inputCount++;
            
            if ( word.equals("STOP") )   {
                repeat = false;
            }
            else if ( word.equalsIgnoreCase("Java") ) {
                javaCount++;
            }
        
        }
        
        outputBox.printLine("Total number of words entered: " + inputCount);
        outputBox.skipLine( 1 );
        outputBox.printLine("'Java' count: " + javaCount );   
                    
    }
    
}