import java.util.Scanner;
import java.util.List;

/**
 * Driver class that processes a file of keypad codes numbers.
 *   @author Dave Reed
 *   @version 9/19/16
 */
public class KeypadDriverB2 {
    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();
        
        ValidCodesB2 valids = new ValidCodesB2(filename);
            
        System.out.print("Enter a code to verify (blank line to quit): ");
        String line = input.nextLine().trim();
        while (line.length() > 0) {
            if (valids.isValid(line)) {
                System.out.println("\t"+line+" is a VALID code");
            }
            else {
                List<String> poss = valids.getPossibles(line);
                if (poss.size() == 0) {
                    System.out.println("\t"+line + " is an INVALID code");                    
                }
                else if (poss.size() == 1) {
                    System.out.println("\t"+poss.get(0) + " is a POSSIBLE code");
                }
                else {
                    System.out.print("\t"+poss.get(0));
                    for (int i = 1; i < poss.size(); i++) {
                        System.out.print(", " + poss.get(i));
                    }
                    System.out.println(" are POSSIBLE codes.");
                }
            }
            System.out.print("Enter a code to verify (blank line to quit): ");
            line = input.nextLine().trim();
        } 
        System.out.println("DONE");
    }
}