// Compute the average of a user-specified file of data values 	
	
import java.util.*;	
import java.io.*;	
	
public class FileAverage {	
	// main(): application entry point	
	public static void main(String[] args) throws IOException {	
		// set up standard input stream	
		Scanner stdin = new Scanner(System.in);	
	
		// determine filename	
		System.out.print("Filename: ");	
		String name = stdin.nextLine();	
	
		// get file stream for text processing	
		File file = new File(name);	
		Scanner fileIn = new Scanner(file);	
	
		// initially no values have been processed	
		int valuesProcessed = 0;	
		double valueSum = 0;	
	
		// process values one by one	
		while (fileIn.hasNextDouble()) {	
			// get the input value	
			double value = fileIn.nextDouble();	
			// add value to running total	
			valueSum += value;	
			// processed another value	
			++valuesProcessed;	
		}	
	
		// ready to compute average	
		if (valuesProcessed > 0) {	
			double average = valueSum / valuesProcessed;	
			System.out.println("Average file data value: " + average);	
		}	
		else {	
			System.err.println(name + ": no values to average");	
		}	
	}	
}	
