Keyboard, a class to simplify Java command-line input.
getChar retrieves the next char, white space or not.Precondition: System.in is open.
Postcondition: The read position has been advanced 1 char.
Return: the next character, white space or not.
peekChar looks at the next char without reading itPrecondition: System.in is open.
Postcondition: The read position has not advanced.
Return: the character in front of the read position.
EatWhiteSpace consumes white space charsPrecondition: 0 or more white space chars lie before the read position.
Postcondition: 0 white space chars lie before the read position.
readChar reads the next non-white-space char.Precondition: System.in is open and contains a non-white-space char.
Postcondition: The read position has advanced beyond the next non-white-space character.
Return: the next non-white-space character.
readWord reads the next 'word' (delimited by white space).Precondition: System.in is open and contains a 'word'.
Postcondition: The read position has advanced beyond the next unbroken sequence of non-white-space chars (skipping any leading white space).
Return: the next unbroken sequence of non-white-space chars.
readLine reads from the read position until the next newline.Precondition: System.in is open.
Postcondition: The read position has advanced beyond the next newline char.
Return: the sequence of chars from the read position to that newline.
readBoolean tries to read the next word as a boolean value.Precondition: System.in is open.
Postcondition: The read position has advanced beyond the next word.
Return: the boolean equivalent of the next word (true, TRUE, tRuE, ... == true; anything else == false).
readByte tries to read the next word as a byte-integer value.Precondition: System.in is open and contains a byte value.
Postcondition: The read position has advanced beyond the next word.
Return: the byte-int-equivalent of the next word.
readShort tries to read the next word as a short-integer value.Precondition: System.in is open and contains a short value.
Postcondition: The read position has advanced beyond the next word.
Return: the short-int-equivalent of the next word.
readInt tries to read the next word as an integer value.Precondition: System.in is open and contains a base-10 int value.
Postcondition: The read position has advanced beyond the next word.
Return: the int equivalent of the next word.
readOctalInt tries to read the next word as an octal integer value.Precondition: System.in is open and contains a base-8 int value.
Postcondition: The read position has advanced beyond the next word.
Return: the base-8 int equivalent of the next word.
readHexInt tries to read the next word as a hexadecimal integer value.Precondition: System.in is open and contains a base-16 int value.
Postcondition: The read position has advanced beyond the next word.
Return: the base-16 int equivalent of the next word.
readLong tries to read the next word as a long-int value.Precondition:: System.in is open and contains a long value.
Postcondition: The read position has advanced beyond the next word.
Return: the long-int equivalent of the next word.
readFloat tries to read the next word as a float value.Precondition: System.in is open and contains a float value.
Postcondition: The read position has advanced beyond the next word.
Return: the float equivalent of the next word.
The version in the book uses Float.parseFloat() to get the value. This was changed to Float.valueOf(myString).floatValue() which is compatible with JDK 1.1. This should have no affect on the semantics of this method.
readDouble tries to read the next word as a double value.Precondition: System.in is open and contains a double value.
Postcondition: The read position has advanced beyond the next word.
Return: the double equivalent of the next word.
The version in the book uses Double.parseDouble() to get the value. This was changed to Double.valueOf(myString).doubleValue() which is compatible with JDK 1.1. This should have no affect on the semantics of this method.
Back to the package documentation index