chn.util
Class ConsoleIO
java.lang.Object
|
+--chn.util.SimpleIO
|
+--chn.util.ConsoleIO
- public class ConsoleIO
- extends SimpleIO
|
Constructor Summary |
ConsoleIO()
Constructs the ConsoleIO object with default delimiters, space,
tab, formfeed. |
ConsoleIO(java.lang.String delims)
Constructs the ConsoleIO object with given delimiters. |
|
Method Summary |
double |
promptDblRange(java.lang.String prompt,
double min,
double max)
Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter. |
double |
promptDouble(java.lang.String prompt)
Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter. |
int |
promptInt(java.lang.String prompt)
Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter. |
int |
promptIntRange(java.lang.String prompt,
int min,
int max)
Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter. |
java.lang.String |
promptLine(java.lang.String prompt)
Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter. |
java.lang.String |
promptToken(java.lang.String prompt)
Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter. |
double |
readDouble()
Reads and returns the next double from the current line. |
int |
readInt()
Reads and returns the next integer from the current line. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ConsoleIO
public ConsoleIO()
- Constructs the ConsoleIO object with default delimiters, space,
tab, formfeed. Newline and return characters terminate the input
of the current line.
ConsoleIO
public ConsoleIO(java.lang.String delims)
- Constructs the ConsoleIO object with given delimiters.
Newline and return characters terminate the input of the current line.
promptToken
public java.lang.String promptToken(java.lang.String prompt)
- Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter.
Reads and returns the next token from the current line. A token is a
String of characters separated by the specified delimiters. If the current
input line has no more unread tokens, reads the first token from the first
non-empty line entered.
- Returns:
- the next String token from input, as determined by delimiters
readInt
public int readInt()
- Reads and returns the next integer from the current line. If the current
input line has no more unread tokens, reads the first token from the first
non-empty line entered.
If the next token is not the correct format for an integer, then a message
is printed, the remainder of the current line is flushed, and this method
reads the next token from the next non-empty line entered.
- Overrides:
readInt in class SimpleIO
- Returns:
- next integer from input
promptInt
public int promptInt(java.lang.String prompt)
- Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter.
Reads and returns the next integer from the current line. If the current
input line has no more unread tokens, reads the first token from the first
non-empty line entered.
If the next token is not the correct format for an integer, then a message
is printed, the remainder of the current line is flushed, and this method
reads the next token from the next non-empty line entered.
- Returns:
- next integer from input
promptIntRange
public int promptIntRange(java.lang.String prompt,
int min,
int max)
- Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter.
Reads and returns the next integer from the current line. If the current
input line has no more unread tokens, reads the first token from the first
non-empty line entered.
If the next token is not the correct format for an integer, then a message
is printed, the remainder of the current line is flushed, and this method
reads the next token from the next non-empty line entered.
precondition: min <= max
- Returns:
- next integer from input that is in range
readDouble
public double readDouble()
- Reads and returns the next double from the current line. If the current
input line has no more unread tokens, reads the first token from the first
non-empty line entered.
If the next token is not the correct format for a double, then a message
is printed, the remainder of the current line is flushed, and this method
reads the next token from the next non-empty line entered.
- Overrides:
readDouble in class SimpleIO
- Returns:
- the next double from input
promptDouble
public double promptDouble(java.lang.String prompt)
- Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter.
Reads and returns the next double from the current line. If the current
input line has no more unread tokens, reads the first token from the first
non-empty line entered.
If the next token is not the correct format for a double, then a message
is printed, the remainder of the current line is flushed, and this method
reads the next token from the next non-empty line entered.
- Returns:
- the next double from input
promptDblRange
public double promptDblRange(java.lang.String prompt,
double min,
double max)
- Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter.
Reads and returns the next double from the current line. If the current
input line has no more unread tokens, reads the first token from the first
non-empty line entered.
If the next token is not the correct format for a double, then a message
is printed, the remainder of the current line is flushed, and this method
reads the next token from the next non-empty line entered.
precondition: min <= max
- Returns:
- the next double from input
promptLine
public java.lang.String promptLine(java.lang.String prompt)
- Flushes any remaining tokens on the current input line,
then prompts the user with the given prompt parameter.
Then reads the next full line input as a String and returns it.
- Returns:
- next line read as a String