/* ***************************************************************************
   *   (c)Copyright notice - 2003 - Uwe "Ed" Beltz, JD.                      *
   *    All rights reserved.                                                 *
   *                                                                         *
   *    DISCLAIMER: The efforts including the development, research, and     *
   *  testing of the following program, and its effectiveness, are solely    *
   *  my effort in conjunction with training in INLS161 - Spring 2003.       *
   *  The author makes no warranty of any kind, expressed or implied,        *
   *  with regard to this, or any associated program.  The author shall not  *
   *  be held liable in any event for incidental or consequential damages    *
   *  arising in connection with, or arising out of, the use, furnishing,    *
   *  or performance of this program.                                        *
   *************************************************************************** */

import javax.swing.*;

public class NameSearchApplet extends JApplet
{

    public void init ()
    {


	String userInput = "";
	String [] groupMembers;
	int i = 0;
	String testName = "";
	int result = 0;

	groupMembers = new String [5];
	for (i = 0 ; i < groupMembers.length ; i++)
	{
	    userInput = JOptionPane.showInputDialog ("Input a user name:");
	    groupMembers [i] = userInput;
	}

	do
	{

	    testName = JOptionPane.showInputDialog ("Enter the name you think is on the list \n or enter QUIT to stop.");


	    for (int counter = 0 ; counter < groupMembers.length ; counter++)
	    {
		if (testName.equalsIgnoreCase (groupMembers [counter]))
		{
		    result = counter;
		    counter = groupMembers.length; //exits user from loop once name is found
		}
		else
		{
		    result = -1;
		}
	    }

	    //show result
	    if (!testName.equals ("QUIT")) //prevents "Name not found" message from showing when user types QUIT to stop
	    {
		if (result == -1)
		    JOptionPane.showMessageDialog (null, "Name not found");
		else
		    JOptionPane.showMessageDialog (null, "Name found at element " + result);
	    }

	} //end do while loop
	while (!testName.equals ("QUIT"));

	JOptionPane.showMessageDialog (null, "You entered 'QUIT'.  Good-bye!");
	System.exit (0);
    }
}

