uwcse.graphics
Class Input

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

public class Input
extends java.lang.Object

A simple I/O class. Can read ints, doubles, strings, and chars. Attempts to robustly handle error inputs, by reprompting the user.


Field Summary
(package private) static int CHAR
           
(package private) static int DOUBLE
           
(package private) static int INTEGER
           
(package private) static int STRING
           
 
Constructor Summary
Input()
          Create a new Input object.
Input(java.lang.String fileName)
          Create a new Input object that reads data from the file of the given name.
 
Method Summary
protected  void display(java.lang.String prompt)
           
 boolean eof()
           
(package private)  java.lang.Object getNextInput(int type)
           
static void main(java.lang.String[] args)
           
static Input newInputFromString(java.lang.String s)
          Create and return a new Input object that reads data from the provided string.
(package private)  java.lang.Object read(int type)
           
(package private)  java.lang.Object read(java.lang.String prompt, int type)
           
 char readChar()
          Read a char without prompting.
 char readChar(java.lang.String prompt)
          Display the given prompt and read an char
 double readDouble()
          Read a double without prompting.
 double readDouble(java.lang.String prompt)
          Display the given prompt and read an double.
 int readInt()
          Read an integer without prompting.
 int readInt(java.lang.String prompt)
          Display the given prompt and read an int.
 java.lang.String readString()
          Read a string without prompting.
 java.lang.String readString(java.lang.String prompt)
          Display the given prompt and read an string.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTEGER

static final int INTEGER

DOUBLE

static final int DOUBLE

STRING

static final int STRING

CHAR

static final int CHAR
Constructor Detail

Input

public Input()
Create a new Input object. Defaults to using the standard input stream.

Input

public Input(java.lang.String fileName)
Create a new Input object that reads data from the file of the given name.
Method Detail

newInputFromString

public static Input newInputFromString(java.lang.String s)
Create and return a new Input object that reads data from the provided string.

display

protected void display(java.lang.String prompt)

getNextInput

java.lang.Object getNextInput(int type)
                        throws java.io.IOException

read

java.lang.Object read(java.lang.String prompt,
                      int type)

read

java.lang.Object read(int type)

eof

public boolean eof()

readString

public java.lang.String readString(java.lang.String prompt)
Display the given prompt and read an string.
Parameters:
prompt - the prompt to display
Returns:
the value read

readChar

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

readDouble

public double readDouble(java.lang.String prompt)
Display the given prompt and read an double.
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 int.
Parameters:
prompt - the prompt to display
Returns:
the int read

readString

public java.lang.String readString()
Read a string without prompting.
Returns:
the value read

readChar

public char readChar()
Read a char without prompting.
Returns:
the value read

readInt

public int readInt()
Read an integer without prompting.
Returns:
the value read

readDouble

public double readDouble()
Read a double without prompting.
Returns:
the value read

main

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