Counting number of entries in a file
I am having problems with counting the number of entries (doubles) in a file as specified by user input. The file opens fine and begins to count, however the accumulator never progresses past 1. also when counting a file with no entries, it never returns as zero, but always 1.
Below is the code of the offending method.
public class Calculate
static String fName;
static int count;
static double num;
static double m;
static double var;
/**the countData method returns the number of entries of type double in file.
@return The value in the entries filed.
public static int countData() throws IOException
String fileName = ""; //file name as input by user
fName = fileName; //passes fileName reference to class variable fname
int entries = 0; //accumulator for number of file entries
count = entries; //passes entries reference to class variable count
//create instance of scanner class to capture user input
Scanner keyboard = new Scanner(System.in);
//prompt user for input
System.out.print("Enter file name: ");
//assign reference to local variable
fileName = keyboard.nextLine();
//create an instance of file class to reference fileName
File file = new File (fileName);
//create instance of scanner class to read from file
Scanner inputFile = new Scanner(file);
//increment the accumulator while more entries exist in the file
//close the file
//if less than 2 entries are in file, prompt user that more are required
if (entries <2)
System.out.println("The file " +fileName +" needs to contain more than 1 entry");
//verifying accumulator is working, which it is not!
System.out.println("number of entries is: " +entries);
}//end of countData method