Package io
Class Keyboard
java.lang.Object
io.Keyboard
public class Keyboard
extends java.lang.Object
Facilitates keyboard input by abstracting details about input parsing, conversions,
and exception handling.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
currentToken
private static java.io.BufferedReader
in
private static java.util.StringTokenizer
reader
-
Constructor Summary
Constructors Constructor Description Keyboard()
-
Method Summary
Modifier and Type Method Description static boolean
endOfLine()
Returns true if there are no more tokens to read on the current input line.private static void
error(java.lang.String errorString)
Prints out a specified error message.private static java.lang.String
getNextInputToken(boolean skip)
Gets the next token from the input, which may come from the current input line or a subsequent one.private static java.lang.String
getNextToken()
Gets the next input token, assuming it may be on subsequent input lines.private static java.lang.String
getNextToken(boolean skip)
Gets the next input token, which may already have been read.static int
readInt()
Returns an integer read from standard input.static java.lang.String
readString()
Returns a string read from standard input.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
currentToken
private static java.lang.String currentToken -
reader
private static java.util.StringTokenizer reader -
in
private static final java.io.BufferedReader in
-
-
Constructor Details
-
Keyboard
public Keyboard()
-
-
Method Details
-
error
private static void error(java.lang.String errorString)Prints out a specified error message.- Parameters:
errorString
- Error text to be printed.
-
getNextToken
private static java.lang.String getNextToken()Gets the next input token, assuming it may be on subsequent input lines. -
getNextToken
private static java.lang.String getNextToken(boolean skip)Gets the next input token, which may already have been read.- Parameters:
skip
- ???- Returns:
- Next input token.
-
getNextInputToken
private static java.lang.String getNextInputToken(boolean skip)Gets the next token from the input, which may come from the current input line or a subsequent one.- Parameters:
skip
- ???- Returns:
- Input token.
-
endOfLine
public static boolean endOfLine()Returns true if there are no more tokens to read on the current input line. -
readString
public static java.lang.String readString()Returns a string read from standard input.- Returns:
- The string entered by the user.
-
readInt
public static int readInt()Returns an integer read from standard input.- Returns:
- The integer entered by the user.
-