|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Keyboard
The Keyboard class, which simplifies input from a keyboard, is based on James Slack's Programming and Problem Solving with Java, published by Brooks/Cole. I have extended it to provide methods that take default values and, therefore, do not throw exceptions. The methods that read various types of floating point numbers have not yet been implemented.
The class file for Slack's original class is available online at
http://krypton.mankato.msus.edu/~slack/javabook/software.html
Constructor Summary | |
Keyboard()
|
Method Summary | |
static int |
readInt()
Waits for the user to type a number, and then returns that number as an int. |
static int |
readInt(int defaultValue)
Waits for the user to type a number, and then returns that number as an int. |
static int |
readInt(java.lang.String prompt)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as an int. |
static int |
readInt(java.lang.String prompt,
int defaultValue)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as an int. |
static int |
readInt(java.lang.String prompt,
int lowValue,
int highValue)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as an int. |
static int |
readInt(java.lang.String prompt,
int lowValue,
int highValue,
int defaultValue)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as an int. |
static long |
readLong()
Waits for the user to type a number, and then returns that number as a long. |
static long |
readLong(long defaultValue)
Waits for the user to type a number, and then returns that number as a long. |
static long |
readLong(java.lang.String prompt)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as a long. |
static long |
readLong(java.lang.String prompt,
int lowValue,
int highValue)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as a long. |
static long |
readLong(java.lang.String prompt,
int lowValue,
int highValue,
long defaultValue)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as a long. |
static long |
readLong(java.lang.String prompt,
long defaultValue)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as a long. |
static short |
readShort()
Waits for the user to type a number, and then returns that number as a short. |
static short |
readShort(short defaultValue)
Waits for the user to type a number, and then returns that number as a short. |
static short |
readShort(java.lang.String prompt)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as a short. |
static short |
readShort(java.lang.String prompt,
int lowValue,
int highValue)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as a short. |
static short |
readShort(java.lang.String prompt,
int lowValue,
int highValue,
short defaultValue)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as a short. |
static short |
readShort(java.lang.String prompt,
short defaultValue)
Displays the given prompt, and then waits for the user to type a number, and then returns that number as a short. |
static java.lang.String |
readString()
Waits for the user to type a line, and then returns all characters the user typed as a string. |
static java.lang.String |
readString(java.lang.String prompt)
Displays the given prompt, and then waits for the user to type a line, and then returns all characters the user typed as a string. |
static java.lang.String |
readString(java.lang.String prompt,
java.lang.String defaultValue)
Displays the given prompt, and then waits for the user to type a line, and then returns all characters the user typed as a string. |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public Keyboard()
Method Detail |
public static java.lang.String readString() throws java.io.IOException
public static java.lang.String readString(java.lang.String prompt) throws java.io.IOException
prompt
- user promptpublic static java.lang.String readString(java.lang.String prompt, java.lang.String defaultValue)
prompt
- user promptdefaultValue
if there was an I/O errorpublic static long readLong() throws java.io.IOException
public static long readLong(long defaultValue)
defaultValue
if there was an I/O errorpublic static long readLong(java.lang.String prompt) throws java.io.IOException
prompt
- user promptpublic static long readLong(java.lang.String prompt, long defaultValue)
prompt
- user promptdefaultValue
if there was an I/O errorpublic static long readLong(java.lang.String prompt, int lowValue, int highValue) throws java.io.IOException
prompt
- user promptpublic static long readLong(java.lang.String prompt, int lowValue, int highValue, long defaultValue)
prompt
- user promptdefaultValue
if there was an I/O error
public static int readInt() throws java.io.IOException
public static int readInt(int defaultValue)
defaultValue
if there was an I/O errorpublic static int readInt(java.lang.String prompt) throws java.io.IOException
prompt
- user promptpublic static int readInt(java.lang.String prompt, int defaultValue)
prompt
- user promptdefaultValue
if there was an I/O errorpublic static int readInt(java.lang.String prompt, int lowValue, int highValue) throws java.io.IOException
prompt
- user promptpublic static int readInt(java.lang.String prompt, int lowValue, int highValue, int defaultValue)
prompt
- user promptdefaultValue
if there was an I/O error
public static short readShort() throws java.io.IOException
public static short readShort(short defaultValue)
defaultValue
if there was an I/O errorpublic static short readShort(java.lang.String prompt) throws java.io.IOException
prompt
- user promptpublic static short readShort(java.lang.String prompt, short defaultValue)
prompt
- user promptdefaultValue
if there was an I/O errorpublic static short readShort(java.lang.String prompt, int lowValue, int highValue) throws java.io.IOException
prompt
- user promptpublic static short readShort(java.lang.String prompt, int lowValue, int highValue, short defaultValue)
prompt
- user promptdefaultValue
if there was an I/O error
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |