Working on a java program that reads a txt file with a bunch of account numbers. User enters account number if it matches the programs responds saying its a valid account number if its not it responds invalid. Here is my class that opens the file and checks to see if it is a valid number. When I run the code it always comes back saying the account number is invalid even though the account number I am testing is valid.
public class Validator {
public boolean isValid(int number) throws IOException {
final int SIZE = 17;
int[] numbers = new int[SIZE];
boolean found = false;
int index = 0;
File file = new File("src/Accounts.txt");
Scanner inputFile = new Scanner(file);
while (inputFile.hasNext() && index < numbers.length) {
numbers[index] = inputFile.nextInt();
index++;
}
while (!found && index < SIZE) {
if (numbers[index] == (number))
found = true;
else
index++;
}
return found;
}
}
Accounts.txtlooks like?reset()method that reloads the file.ArrayListis not an array. AnArrayListuses arrays but I wouldn't consider it okay if you've been told you have to use an array. I'd have to see the rules to be sure though.