/* Code Sample to help Read a file and get started on Baby Names
   Period 2 Jan 5th, 2011
*/
   import java.io.*;    // for File
   import java.util.*;  // for Scanner
   public class DemoFileRead {
      public static void main(String[] args) throws FileNotFoundException {
   		// Alternative way to establish the Scanner to read the file   	
			//File jello = new File("names.txt");
      	//Scanner input = new Scanner(jello);
			Scanner input = new Scanner(new File("names.txt"));
			// Assume the first name has already been read from console      	
         String firstName = "Austin";
      	// Use method to get the line of stats in the names.txt file	
         String line = findName(input, firstName);  
			
         if (line.length() == 0) {
            System.out.println("Name not found"); //Not the correct format
         } 
         else {       
            System.out.println(line);
         	// Print the meaning, and graph the results
         }
      }
   	
		// This uses a method to Find the first name in the names list 
		//   and returns the line of stats or whatever 
   	public static String findName (Scanner input, String firstName) {
         String line = "";
         boolean found = false; 
         while (input.hasNextLine() && (!found)) {
            String thisLine = input.nextLine();
            if (firstName.equalsIgnoreCase(thisLine.substring(0,thisLine.indexOf(" ")))) {
               found = true; 
					line = thisLine;
            }
         }
         return line;
      }
   
   }
