import java.util.Scanner;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Driver class that processes a file of keypad codes numbers.
 *   @author Dave Reed
 *   @version 9/19/16
 */
public class KeypadDriverA1 {
    public static void main(String[] args) {
        System.out.print("Enter the file of valid codes: ");
        Scanner input = new Scanner(System.in);
        String filename = input.nextLine();
        
        List<String> codes = new ArrayList<String>();
        try {
            Scanner infile = new Scanner(new File(filename));
            while (infile.hasNext()) {
                String code = infile.next();
                codes.add(code.trim());
            }
            infile.close();
        }
        catch (java.io.FileNotFoundException e) {
            System.out.println("File not found.");
        }        
            
        System.out.print("Enter a code to verify (blank line to quit): ");
        String line = input.nextLine().trim();
        while (line.length() > 0) {
            if (codes.contains(line)) {
                System.out.println("\t"+line+" is a VALID code");
            }
            else {
                System.out.println("\t"+line + " is an INVALID code");                    
            }
            
            System.out.print("Enter a code to verify (blank line to quit): ");
            line = input.nextLine().trim();
        } 
        System.out.println("DONE");
    }
}