JSFiddle - React, Tailwind, and code Playground

by MegaScience

JavaScript

/**
 * Chapter 7
 * Programming Challenge 3: Charge Account Validation
 * The Validator class provides a method to
 * validate account numbers.
 */
public class Validator {
    // Array of valid numbers
    private int[] valid = {
        5658845, 4520125, 7895122, 8777541,
        8451277, 1302850, 8080152, 4562555,
        5552012, 5050552, 7825877, 1250255,
        1005231, 6545231, 3852085, 7576651,
        7881200, 4581002
    };

    /**
     * isValid method
     * This method uses a sequential search to
     * determine whether the argument appears in
     * in the array of valid numbers.
     */

    public boolean isValid(int number) {
        boolean found = false; // Flag
        int index = 0; // Array index

        while (!found && index < valid.length) {
            if (valid[index] == number)
                found = true;
            else
                index++;
        }

        return found;
    }

	File file = new File ("AccountNumbers.txt");
	Scanner inFile = new Scanner(file);
	String input;
	List<Integer> list = new ArrayList<Integer>();
	while((input=inFile.readLine()) != null && input.length() != 0) {
		int number = Integer.parseInt(input);
		list.add(number);
	}
	list.toArray();
}