

import java.io.*;


/**
 *  A class to read strings and numbers from a file. This class is suitable for
 *  beginning Java programmers. It constructs the necessary buffered reader,
 *  handles I/O exceptions, and converts strings to numbers.
 *
 *@author     jeff
 *@created    May 15, 2003
 */


public class FileInputReader {

	private FileReader fr;

	private BufferedReader br;



	/**
	 *  Constructs a console reader from a file
	 *
	 *@param  filename  the filename of the input
	 */

	public FileInputReader(String filename) {

		try {
			fr = new FileReader(filename);

		} catch (FileNotFoundException e) {

			System.out.println("File not found:" + filename);

			System.exit(-1);

		}
		/*
		 *  catch
		 */
		br = new BufferedReader(fr);

	}


	/*
	 *  Cat
	 */

	/**
	 *  Reads a line of input and converts it into an integer. The input line must
	 *  contain nothing but an integer. Not even added white space is allowed.
	 *
	 *@return    the integer that the user typed
	 */

	public int readInt() {
		String inputString = readLine();

		int n = 0;


		try {

			n = Integer.parseInt(inputString);

		} catch (NumberFormatException nfe) {

			System.out.println(nfe);

			System.exit(-1);

		}


		return n;
	}



	/**
	 *  Reads a line of input and converts it into a floating- point number. The
	 *  input line must contain nothing but a nunber. Not even added white space is
	 *  allowed.
	 *
	 *@return    the number that the user typed
	 */

	public double readDouble() {
		String inputString = readLine();

		double x = 0.0;


		try {

			x = Double.parseDouble(inputString);

		} catch (NumberFormatException nfe) {

			System.out.println(nfe);

			System.exit(-1);

		}


		return x;
	}



	/**
	 *  Reads a line of input. In the (unlikely) event of an IOException, the
	 *  program terminates.
	 *
	 *@return    the line of input that the user typed, null at the end of input
	 */

	public String readLine() {

		String inputLine = "";


		try {
			inputLine = br.readLine();

		} catch (IOException e) {
			System.out.println(e);

			System.exit(-1);

		}


		return inputLine;
	}



	/**
	 *  close the file
	 */

	public void close() {

		try {
			br.close();

		} catch (IOException e) {
			System.out.println(e);

			System.exit(-1);

		}

	}


}
/*
 *  public class FileInputReader
 */

