|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object Terminal
Terminal provides a user-friendly interface to the standard System input and output streams (in, out, and err).
A Terminal is an object. In general, one is expected to instantiate just one Terminal. Although one might instantiate several, all will share the same System streams.
A Terminal may either explicitly echo input, or not. Echoing input is useful, for example, when testing with I/O redirection.
Inspired by Cay Horstmann's Console Class.
Constructor Summary | |
Terminal()
Construct a Terminal that doesn't echo input. |
|
Terminal(boolean echo)
Construct a Terminal. |
Method Summary | |
void |
errPrint(boolean b)
Print a Boolean value ( true or false )
to standard err (without a newline). |
void |
errPrint(char ch)
Print character to standard err (without a newline). |
void |
errPrint(char[] s)
Print character array to standard err (without a newline). |
void |
errPrint(double val)
Print a double-precision floating point number to standard err (without a newline). |
void |
errPrint(float val)
Print a floating point number to standard err (without a newline). |
void |
errPrint(int val)
Print integer to standard err (without a newline). |
void |
errPrint(long val)
Print a long integer to standard err (without a newline). |
void |
errPrint(Object val)
Print Object to standard err (without a newline). |
void |
errPrint(String str)
Print string to standard err (without a newline). |
void |
errPrintln()
Print a newline to standard err, terminating the current line. |
void |
errPrintln(boolean b)
Print a Boolean value ( true or false )
to standard err, followed by a newline. |
void |
errPrintln(char ch)
Print character to standard err, followed by a newline. |
void |
errPrintln(char[] s)
Print a character array to standard err, followed by a newline. |
void |
errPrintln(double val)
Print a double-precision floating point number to standard err, followed by a newline. |
void |
errPrintln(float val)
Print floating point number to standard err, followed by a newline. |
void |
errPrintln(int val)
Print integer to standard err, followed by a newline. |
void |
errPrintln(long val)
Print a long integer to standard err, followed by a newline. |
void |
errPrintln(Object val)
Print Object to standard err, followed by a newline. |
void |
errPrintln(String str)
Print string to standard err, followed by a newline. |
static void |
main(String[] args)
Unit test for Terminal. |
void |
print(boolean b)
Print a Boolean value ( true or false )
to standard output (without a newline). |
void |
print(char ch)
Print character to standard output (without a newline). |
void |
print(char[] s)
Print character array to standard output (without a newline). |
void |
print(double val)
Print a double-precision floating point number to standard output (without a newline). |
void |
print(float val)
Print a floating point number to standard output (without a newline). |
void |
print(int val)
Print integer to standard output (without a newline). |
void |
print(long val)
Print a long integer to standard output (without a newline). |
void |
print(Object val)
Print Object to standard output (without a newline). |
void |
print(String str)
Print string to standard output (without a newline). |
void |
println()
Print a newline to standard output, terminating the current line. |
void |
println(boolean b)
Print a Boolean value ( true or false )
to standard output, followed by a newline. |
void |
println(char ch)
Print character to standard output, followed by a newline. |
void |
println(char[] s)
Print a character array to standard output, followed by a newline. |
void |
println(double val)
Print a double-precision floating point number to standard output, followed by a newline. |
void |
println(float val)
Print floating point number to standard output, followed by a newline. |
void |
println(int val)
Print integer to standard output, followed by a newline. |
void |
println(long val)
Print a long integer to standard output, followed by a newline. |
void |
println(Object val)
Print Object to standard output, followed by a newline. |
void |
println(String str)
Print string to standard output, followed by a newline. |
char |
readChar()
Read a character from the Terminal. |
char |
readChar(String prompt)
Read a character from the Terminal. |
char |
readCharOnce()
Read a character from the Terminal. |
char |
readCharOnce(String prompt)
Read a character from the Terminal. |
double |
readDouble()
Read a double-precision floating point number, terminated by a newline, from the Terminal. |
double |
readDouble(String prompt)
Read a double-precision floating point number, terminated by a newline, from the Terminal. |
double |
readDoubleOnce()
Read a double-precision floating point number, terminated by a newline, from the Terminal. |
double |
readDoubleOnce(String prompt)
Read a double-precision floating point number, terminated by a newline, from the Terminal. |
int |
readInt()
Read an integer, terminated by a new line, from the Terminal. |
int |
readInt(String prompt)
Read an integer, terminated by a new line, from the Terminal. |
int |
readIntOnce()
Read an integer, terminated by a new line, from the Terminal. |
int |
readIntOnce(String prompt)
Read an integer, terminated by a new line, from the Terminal. |
String |
readLine()
Read a line (terminated by a newline) from the Terminal. |
String |
readLine(String prompt)
Read a line (terminated by a newline) from the Terminal. |
String |
readWord()
Read a word from the Terminal. |
String |
readWord(String prompt)
Read a word from the Terminal. |
String |
readWordOnce()
Read a word from the Terminal. |
String |
readWordOnce(String prompt)
Read a word from the Terminal. |
boolean |
readYesOrNo()
Read "yes" or "no" from the Terminal. |
boolean |
readYesOrNo(String prompt)
Read "yes" or "no" from the Terminal. |
boolean |
readYesOrNoOnce()
Read "yes" or "no" from the Terminal. |
boolean |
readYesOrNoOnce(String prompt)
Read "yes" or "no" from the Terminal. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Terminal()
public Terminal(boolean echo)
echo
- whether or not input should be echoed.Method Detail |
public void errPrint(boolean b)
true
or false
)
to standard err (without a newline).
b
- Boolean to print.public void errPrint(char ch)
ch
- character to print.public void errPrint(char[] s)
s
- character array to print.public void errPrint(double val)
val
- number to print.public void errPrint(float val)
val
- number to print.public void errPrint(int val)
val
- integer to print.public void errPrint(long val)
val
- integer to print.public void errPrint(Object val)
val
- Object to print.public void errPrint(String str)
str
- String to print.public void errPrintln()
public void errPrintln(boolean b)
true
or false
)
to standard err, followed by a newline.
b
- Boolean to print.public void errPrintln(char ch)
ch
- character to print.public void errPrintln(char[] s)
s
- character array to print.public void errPrintln(double val)
val
- number to print.public void errPrintln(float val)
val
- number to print.public void errPrintln(int val)
val
- integer to print.public void errPrintln(long val)
val
- long integer to print.public void errPrintln(Object val)
val
- Object to printpublic void errPrintln(String str)
str
- String to printpublic static void main(String[] args)
args
- command line arguments:
-e echo all input.
public void print(boolean b)
true
or false
)
to standard output (without a newline).
b
- Boolean to print.public void print(char ch)
ch
- character to print.public void print(char[] s)
s
- character array to print.public void print(double val)
val
- number to print.public void print(float val)
val
- number to print.public void print(int val)
val
- integer to print.public void print(long val)
val
- integer to print.public void print(Object val)
val
- Object to print.public void print(String str)
str
- String to print.public void println()
public void println(boolean b)
true
or false
)
to standard output, followed by a newline.
b
- Boolean to print.public void println(char ch)
ch
- character to print.public void println(char[] s)
s
- character array to print.public void println(double val)
val
- number to print.public void println(float val)
val
- number to print.public void println(int val)
val
- integer to print.public void println(long val)
val
- long integer to print.public void println(Object val)
val
- Object to printpublic void println(String str)
str
- String to printpublic char readChar()
public char readChar(String prompt)
prompt
- output string to prompt for input.
public char readCharOnce()
RuntimeException
- if it reads an empty line.public char readCharOnce(String prompt)
prompt
- output string to prompt for input.
RuntimeException
- if it reads an empty line.public double readDouble()
public double readDouble(String prompt)
prompt
- output string to prompt for input.
public double readDoubleOnce() throws NumberFormatException
NumberFormatException
- for a badly formed number.public double readDoubleOnce(String prompt) throws NumberFormatException
prompt
- output string to prompt for input.
NumberFormatException
- for a badly formed number.public int readInt()
public int readInt(String prompt)
prompt
- output string to prompt for input.
public int readIntOnce() throws NumberFormatException
NumberFormatException
- for a badly formed integer.public int readIntOnce(String prompt) throws NumberFormatException
prompt
- output string to prompt for input.
NumberFormatException
- for a badly formed integer.public String readLine()
public String readLine(String prompt)
prompt
- output string to prompt for input.
public String readWord()
public String readWord(String prompt)
prompt
- output string to prompt for input.
public String readWordOnce()
RuntimeException
- if it reads an empty line.public String readWordOnce(String prompt)
prompt
- output string to prompt for input.
RuntimeException
- if it reads an empty line.public boolean readYesOrNo()
public boolean readYesOrNo(String prompt)
prompt
- output string to prompt for input.
public boolean readYesOrNoOnce()
RuntimeException
- on improper input.public boolean readYesOrNoOnce(String prompt)
prompt
- output string to prompt for input.
RuntimeException
- on improper input.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |