/*
 * ConsoleUtil.java
 *
 * Created on 26 Ноябрь 2009 г., 14:05
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package fptrtest;

/**
 *
 * @author V.Kravtsov
 */

import java.io.*;

public class ConsoleUtil {
    
    private final static String separator = 
        "============================================================";
    private static final BufferedReader in = new BufferedReader(
        new InputStreamReader(System.in));
    
    /** Creates a new instance of ConsoleUtil */
    public ConsoleUtil() {
    }
 
    public void printSeparator()
    {
        System.out.println("");
        System.out.println(separator);
    }
    
    public String readLine(String text)
    throws Exception
    {
        System.out.print(text);
        return in.readLine();
    }
    
    /** Read long input **/
    public long readLong(String text)
    throws Exception
    {
        long result = 0;
        while (true)
        {
            String line = readLine(text);
            try
            {
                
                result = Long.parseLong(line);
                break;
            }
            catch(NumberFormatException e){
                // ignore invalid input
            }
        }
        return result;
    }
    
    /** Read menu item **/
    public int readMenuItem()
    throws Exception
    {
        return (int)readLong("Select menu item: ");
    }
    
    
}
