package librairyMR;

import java.io.*;
import java.util.*;

/**
 * @author martin
 *
 */
public class ConsoleIO {
	/*classe de méthode statique
	 * ne doit pas etre initialisé*/
	private ConsoleIO(){}

	/*petit objet de support*/
	private static BufferedReader _in = new BufferedReader(new InputStreamReader(System.in));
	private static Scanner _in2 = new Scanner(System.in);

	//get string from keyboard
	/**
	 * get String from keyboard using buffered reader
	 * @return String
	 * @throws IOException if the keyboard fail
	 */
	public static String getStr() throws IOException{
		return _in.readLine();
	}

	/**
	 * get String from keyboard using scanner
	 * @return String
	 * @throws IOException if the keyboard fail
	 */
	public static String getStr2() throws IOException{
		return _in2.nextLine();
	}


	/**
	 * prompt user to write a number on the keyboard
	 * @return int
	 * @throws IOException if he fail miserably
	 */
	public static int getInt() throws IOException{
		int val;

		do{
			System.out.println("entrez un nombre");
			try{
				val = Integer.parseInt(ConsoleIO.getStr2());
			}catch(NumberFormatException e){
				val = 0;
				System.out.println(" Un nombre j'ai dit !!!!");
			}
		}while(val == 0);

		return val;
	}
}
