uwcse.io
Class Input

java.lang.Object
  |
  +--uwcse.io.Input

public class Input
extends java.lang.Object

A simple I/O class. Can read ints, doubles, strings, chars, and booleans. Attempts to robustly handle error inputs, by reprompting the user. Can read from the keyboard or from a file (in which case no prompts are issued). Alternative operations are available to read from pop-up windows.


Constructor Summary
Input()
          Create a new Input object to read from the terminal window or console.
Input(java.lang.String fileName)
          Create a new Input object that reads data from the file of the given name.
 
Method Summary
static void main(java.lang.String[] args)
          A test method
 boolean readBoolean(java.lang.String prompt)
          Display the given prompt and read a boolean, i.e., the user has to type one of yes, no, true, or false, either capitalized or not, or any non-empty prefix thereof, e.g., y, t, fa, etc.
 boolean readBooleanDialog(java.lang.String prompt)
          Display the given prompt and read a boolean, using a pop-up dialog window, i.e., the user has to type one of yes, no, true, or false, either capitalized or not, or any non-empty prefix thereof, e.g., y, t, fa, etc.
 char readChar(java.lang.String prompt)
          Display the given prompt and read a character
 char readCharDialog(java.lang.String prompt)
          Display the given prompt and read a character, using a pop-up dialog window.
 double readDouble(java.lang.String prompt)
          Display the given prompt and read a double.
 double readDoubleDialog(java.lang.String prompt)
          Display the given prompt and read a double, using a pop-up dialog window.
 int readInt(java.lang.String prompt)
          Display the given prompt and read an integer.
 int readIntDialog(java.lang.String prompt)
          Display the given prompt and read an integer, using a pop-up dialog window.
 java.lang.String readString(java.lang.String prompt)
          Display the given prompt and read a single word of input.
 java.lang.String readStringDialog(java.lang.String prompt)
          Display the given prompt and read a single word of input, using a pop-up dialog window.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Input

public Input()
Create a new Input object to read from the terminal window or console.

Input

public Input(java.lang.String fileName)
Create a new Input object that reads data from the file of the given name. No prompts are printed when reading from a file. Throws a nasty exception if the file can't be found.
Parameters:
fileName - the name of the file to read from
Method Detail

main

public static void main(java.lang.String[] args)
A test method

readBoolean

public boolean readBoolean(java.lang.String prompt)
Display the given prompt and read a boolean, i.e., the user has to type one of yes, no, true, or false, either capitalized or not, or any non-empty prefix thereof, e.g., y, t, fa, etc.
Parameters:
prompt - the prompt to display
Returns:
the boolean read

readBooleanDialog

public boolean readBooleanDialog(java.lang.String prompt)
Display the given prompt and read a boolean, using a pop-up dialog window, i.e., the user has to type one of yes, no, true, or false, either capitalized or not, or any non-empty prefix thereof, e.g., y, t, fa, etc.
Parameters:
prompt - the prompt to display
Returns:
the boolean read

readChar

public char readChar(java.lang.String prompt)
Display the given prompt and read a character
Parameters:
prompt - the prompt to display
Returns:
the value read

readCharDialog

public char readCharDialog(java.lang.String prompt)
Display the given prompt and read a character, using a pop-up dialog window.
Parameters:
prompt - the prompt to display
Returns:
the value read

readDouble

public double readDouble(java.lang.String prompt)
Display the given prompt and read a double.
Parameters:
prompt - the prompt to display
Returns:
the value read

readDoubleDialog

public double readDoubleDialog(java.lang.String prompt)
Display the given prompt and read a double, using a pop-up dialog window.
Parameters:
prompt - the prompt to display
Returns:
the value read

readInt

public int readInt(java.lang.String prompt)
Display the given prompt and read an integer.
Parameters:
prompt - the prompt to display
Returns:
the int read

readIntDialog

public int readIntDialog(java.lang.String prompt)
Display the given prompt and read an integer, using a pop-up dialog window.
Parameters:
prompt - the prompt to display
Returns:
the int read

readString

public java.lang.String readString(java.lang.String prompt)
Display the given prompt and read a single word of input.
Parameters:
prompt - the prompt to display
Returns:
the value read

readStringDialog

public java.lang.String readStringDialog(java.lang.String prompt)
Display the given prompt and read a single word of input, using a pop-up dialog window.
Parameters:
prompt - the prompt to display
Returns:
the value read