My program compiles and runs but its not outputting correctly. The program should check the file valid_accounts.txt and compare it to the users input. If the account is found int the valid_accounts.txt the output should display "That account number is valid.". I get "You did not enter a valid account number." whether the input is correct or not. Any help would be greatly appreciated.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.Vector;
public class ChargeAccount
{
static Vector<Integer> validChargeAccountNumbers = new Vector<Integer>();
public static void main(String[] args)
{
//load the file
readMyFile("valid_accounts.txt");
Scanner in = new Scanner(System.in);
// Ask the user for an account number
System.out.print("Please enter an account number: ");
// Get the number from the user
int number = in.nextInt();
// Check to see if the number is valid
if (isValid(number) == true)
{
System.out.println("That account number is valid.");
}
else
{
System.out.println("You did not enter a valid account number.");
}
}
// Check to see if an account number is valid by comparing it to the
// entries in the vector validChargeAccountNumbers
public static boolean isValid(int number)
{
return validChargeAccountNumbers.contains(number);
}
public static void readMyFile(String nameFile)
{
String record = null;
BufferedReader reader = null;
FileReader fr = null;
int recCount = 0;
// Code to read the file and store each account into the vector
// validChargeAccountNumbers
}
}