My program checks a valid_accounts. txt to see if the input account number is valid. When i run the code with either a correct or incorrect code it outputs "the code is invalid" Can anyone help with this? I do believe it is something simple. I have been working all day on this program.
Code:
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
}
}
Comment