/* The KeyboardReader class creates a package with methods for reading doubles, integers, strings, characters  and formatting doubles. */

package simpleIO;

import java.io.*;
import java.text.*;

public class KeyboardReader
{
     static BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));

     // Reads a double from the keyboard and returns it to the calling method.
     public static double readDouble ( )
     {
          double number;
          try
          {
               number = Double.valueOf (stdin.readLine ( )).doubleValue ( );
          } catch (IOException e)  { number = 0;}
          catch (NumberFormatException x) { number = 0;}
      return number;
     } // method readDouble
 
     // Formats a double for string output with two decimal places.
     public static String decimals (double number)
     {
          DecimalFormat decFor = new DecimalFormat ( );
          decFor.setMaximumFractionDigits (2);
          decFor.setMinimumFractionDigits (2);
          return decFor.format (number);
     } // method decimals
 
     // Reads an integer from the keyboard and returns it to the calling method.
     public static int readInteger ()
     {
          int number;
          try
          {
               number = Integer.parseInt (stdin.readLine ());
          } catch (IOException e) { number = 0;}
          catch (NumberFormatException x) { number = 0;}
          return number;
     } // method readInteger
 
    // Reads a string from the keyboard and returns it to the calling method.
     public static String readString ()
     {
          String string;
          try
          {
               string = stdin.readLine ();
          } catch (IOException e) { string = "";}
          return string;
     } // method readString

     // Reads a character from the keyboard and returns it to the calling method.
     public static char readChar ()
     {
          char ch;
          try
          {
               ch = (char) stdin.read ();
          } catch (IOException e) { ch = ' ';}
          return ch;
     } // method readChar
} // public class KeyboardReader