import java.io.File;
import java.util.Scanner;


public class Question4 {

	public static void main(String[] args) {
		
		// Instantiate File and Scanner objects
		File foobar;
		Scanner input;
		
		// Set up file
		// Named such for consistency; file extensions really don't do anything.
		foobar = new File ("files\\Question4-ages.dat.txt");
		
		// Read file 
		try {
			
			// Set up Scanner
			input = new Scanner(foobar);
			
			// Set up variables
			int lowestAge=Integer.MAX_VALUE, highestAge=Integer.MIN_VALUE; // Safeguard
			int buffer = 0;
			
			// Process ages
			while (input.hasNextInt()) {
				buffer = input.nextInt();
				if (buffer < lowestAge) { // If lower than current lowest age
					lowestAge = buffer;
				} else if (buffer > highestAge) { // If higher than current highest age
					highestAge = buffer;
				}
			}
			
			// Clean up
			input.close();
			
			// Print results
			System.out.println("Lowest age: " + lowestAge);
			System.out.println("Highest age: " + highestAge);
		
		} catch (java.io.FileNotFoundException e) {
			
			// From "input = new Scanner(foobar);"
			System.err.println("Error: file " + foobar + " not found.");
			e.getMessage();
			System.exit(1);
		}

	}

}
