/*
 * Created on 12/08/2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package compphys_640364;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author pdonelan
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class KeyboardReader {
	BufferedReader keyboardReader = new BufferedReader(new InputStreamReader(
			System.in));

	// prompt the user, then read a string from the keyboard, terminated by
	// either a 'return' or 'enter'
	// use a try/catch block for error handling
	public void write(String string) {
		System.out.println(string);
	}

	public String getString(String prompt) {
		try {
			System.out.print(prompt);
			return keyboardReader.readLine();
		} catch (Exception exception) {
			return exception.toString();
		}
	}

	// read a string and then convert it to an integer to be returned
	public int getInt(String prompt) {
		String string = getString(prompt);
		return Integer.parseInt(string);
	}

	// read a string and then convert it to an double to be returned
	public double getDouble(String prompt) {
		String string = getString(prompt);
		return Double.parseDouble(string);
	}
}


