/**** DATA LIST ******************************\
A social web-site needs to store information about
their users.  In this case, they store:
  Name#Phone$email
for each user.  The program stores a list of users
in an array, using one long String for each user.
This simple starting program will search for
any text in any of the entries.  For example,
searching for ".de" will find all the email
address with a German top-level-domain.
\*********************************************/


public class DataList
{
  String[] data =
  {
    "Dave Mulkey#12345-67890$davemulkey@yahoo.de" ,
    "Elliott Gould#0$Egould@actors.info" ,
    "Madonna Ciccone#345-284-9876$madonna@gmail.co.uk" ,
    "Fred Flintstone#111-222333$ff@old.com" ,
    "Rude Dude#666666666$music.biz" ,
    "Angela Merkel#109-123456789$angie@berlin.de" ,
    "Your Name#00000-00000$yourname@yourdomain.top" ,
    "Bundes Bahn#12345-67890$bbahn@rmv.de" ,
    "John Glenn#415-999-5555$johnglenn@nasa.gov" ,
    "Glenn Snowden#000$none@hidden.ru" 
  };
 
  public DataList()
  {
    String target = "";
    while(true)
    {
      boolean found = false;
     
      target = input("Type text to find");
      if(target.length()==0)
      {  System.exit(0); }
     
      for(int c = 0; c < data.length; c = c+1)
      {
        if(data[c].indexOf(target)>=0 )
        {
          output(data[c]);
          found = true;             
        }
      }        
     
      if(found == false)
      {
        output("not found");
      }

    }    
  } 
 
  public static void main(String[] args)
  {  new DataList();  }
 
  public String input(String prompt)
  { return javax.swing.JOptionPane.showInputDialog(null,prompt); }

  public void output(String message)
  {  javax.swing.JOptionPane.showMessageDialog(null,message);  }
}
/******************************************

Practice

1 - Download the program.  Copy the DATA from the top.
    Run the program.  Paste the data into the TextBox.
    Click [Read Data].  Click [Search]. 
    Search for:
    - someone named "Rude Dude"
    - someone whose phone number contains "345"
    - only people whose phone number STARTS with "345"
    - someone whose LAST NAME is "Snowden"
    - someone whose email ends with "de"

2 - Explain why searching for "de" finds other things
    besides the "de" email addresses.
   
3 - Create a button called [find .de].
    This should output all the people with emails in .de
   
4 - The sample data is only a small sample.
    Assume that a much larger set of data is available
    in a text file somewhere. Create a [How Many] button
    that outputs the number of people in the list.
    For the sample data, this would output 10.

5 - Explain how it is possible that two different people
    might have EXACTLY THE SAME email address.
   
6 - Create a [Find Email] button.  This should do the following:
    - input the desired email address, all of it
    - loop through the data array
    - find the $ sign in each data line
    - extract all the text AFTER the $ sign
    - check whether this matches the target address
    - if it matches, output the entire line of data
   
7 - Any phone number that starts with 0 is a fake number.
    Find and output all the people with fake phone numbers.

*******************************************/