/*
Programmer:	<your name>
CSC 211 - Section 2							Lab #1						Sept 09, 2007

Input:	A simple line of text made up of a few words (separated by spaces).
Output:	The first and (famous) last words in that line of text.
*/

import javax.swing.*;
import java.util.*;


public class Lab01  //	To name our first program
{
    //	There is a lot of "magic" going on in this code.  We will go over it progresssively
    //  over the semester.  For today, just try to get a feel for the "Java way"

    public static void main (String[] args)
    {
        //  Here I declare variables, which are "containers" to store data.
        //  A variable is characterized by its name (identifier), its type, and
        //  its content.  Here I declared a variable named "theWholeLine" that will
        //  store the characters of a line of text
    	String	theWholeLine;					//	To hold the whole line of input
    	String	someString;						//	To perform "computations" on strings
    	String	firstWord, lastWord;			//	To hold the first and last words
    	int		startPosition, endPosition;		//	To determine the first and last
    											//		word positions within the input
    	
    	// say "Hello!" to the world

        //  ask "Could you say a few words?" and store the string returned
        //  in theWholeline
        theWholeLine = JOptionPane.showInputDialog(null, "Say something");

        String myOutput = "You have typed in "
    					  + theWholeLine.length()	//	This will display very basic
    					  + " characters." ;		//		statistics on the input

        //  Here I print information to the console
        System.out.println(myOutput);

    	
    	someString = theWholeLine.trim();		//	In order to determine the first word,
    											//		we start with the whole line, and
    											//		we remove any space at either end

    	//	After that trimming, the first word must be beginning at position 0
    	startPosition = 0;	
    	
    	endPosition = someString.indexOf(" ");	//	It must also be ending just prior to
    											//	the first space (assuming no punctuation)

    	//	Therefore, we have the first word as:
    	firstWord = someString.substring(startPosition, endPosition);

    	myOutput = "Your first word is: "  + firstWord  + ", " ;
    	
    	/*
    		The following part of the program is not doing its job ...
    	*/
    	lastWord = "famous_last_word";			//	P L E A S E   H E L P ! ! !

        myOutput = "and your last word is: "
    							 + lastWord
    							 + "." ;

        //  I can also display a message to the user by using a message window
    	JOptionPane.showMessageDialog(null, "Bye!");

    }	//	end of main
}	//	end of Lab01
