|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--KeyboardReader
A class to read strings and numbers from the keyboard.
This class is intended for beginning Java programmers. It constructs the necessary buffered reader, converts strings to numbers, and handles exceptions.
The methods in this class are static methods. This means that they can be invoked using the class name, without needing to create a KeyboardReader object.
The following examples illustrate how to use this class to read from the keyboard:
int x = KeyboardReader.readInt(); // read an int double y = KeyboardReader.readDouble(); // read a double String s = KeyboardReader.readString(); // read a StringThis class also defines return values to indicate end-of-information (EOI) and data conversion errors.
The default behavior of the readInt() and readDouble() methods is to write a comment to the screen in response to inappropriate data. This behavior may be controlled by the ERROR_MESSAGES field.
Field Summary | |
static double |
EOI_DOUBLE
Returned by the readDouble() method to indicate EOI. |
static int |
EOI_INT
Returned by the readInt() method to indicate EOI. |
static java.lang.String |
EOI_STRING
Returned by the readString() method to indicate EOI. |
static double |
ERROR_DOUBLE
Returned by the readDouble() method to indicate an error. |
static int |
ERROR_INT
Returned by the readInt() method to indicate an error. |
static boolean |
ERROR_MESSAGES
Controls the output of error messages to the console in response to inappropriate input. |
static java.lang.String |
ERROR_STRING
Returned by the readString() method to indicate an error. |
Method Summary | |
static void |
main(java.lang.String[] args)
Tests the KeyboardReader methods. |
static double |
readDouble()
Reads a line of input and converts it into a double. |
static int |
readInt()
Reads a line of input and converts it into an int. |
static java.lang.String |
readString()
Reads a line of character input. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int EOI_INT
public static final double EOI_DOUBLE
public static final java.lang.String EOI_STRING
public static final int ERROR_INT
public static final double ERROR_DOUBLE
public static final java.lang.String ERROR_STRING
public static boolean ERROR_MESSAGES
Method Detail |
public static int readInt()
public static double readDouble()
public static java.lang.String readString()
public static void main(java.lang.String[] args)
This method would not normally be invoked by users of the KeyboardReader class.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |