All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class rebelsky.io.SimpleInput

java.lang.Object
   |
   +----rebelsky.io.SimpleInput

public class SimpleInput
extends Object
A simple input system for beginning programmers. Permits reading of basic data types without delving into the workings of the various Java libraries. Does not throw exceptions.

If something goes wrong with one of the read methods, an error value is returned. You can determine what that value is with getErrorXXX (e.g., getErrorInt) and set the value with setErrorXXX). You can also use checkError to determine whether a value you received is intended to mark an error.

Copyright (c) 1998 Samuel A. Rebelsky. All rights reserved.

Version:
1.1 of January 1998
Author:
Samuel A. Rebelsky

Constructor Index

o SimpleInput()
Create a new object to read from standard input.

Method Index

o checkError()
See if the last input operation we did returned an error.
o eof()
See if we're at the end of the file.
o eoln()
See if we're at the end of the line.
o getErrorDouble()
Get the double used to report errors.
o getErrorInt()
Get the integer used to report errors.
o getErrorString()
Get the string used to report errors.
o peek()
Look at the next character in the buffer.
o readChar()
Read the next character (including whitespace) from the given input.
o readDouble()
Read a double from the given input.
o readInt()
Read an integer from the given input.
o readLine()
Read one line from the given input and return that line without any carriage return or other line-terminating character.
o readLineDouble()
Read a double from the current line and then skip to the end of the line.
o readLong()
Read a long integer from the given input.
o readString()
Read the next nonempty string, skipping any intervening whitespace (including carriage returns).
o setErrorDouble(double)
Set the double used to report errors.
o setErrorInt(int)
Set the integer used to report errors.
o setErrorString(String)
Set the error string.
o skipWhite()
Skip over any whitespace until we reach a non-whitespace character or the end of file.

Constructors

o SimpleInput
 public SimpleInput()
Create a new object to read from standard input.
pre: standard input has not been modified.
post: the object will read from standard input.

Methods

o checkError
 public boolean checkError()
See if the last input operation we did returned an error.
pre: We've completed an input operation.
post: Returns true if the last operation failed. Returns false otherwise.

o eof
 public boolean eof()
See if we're at the end of the file.
pre: (none)
post: if no input has been read, input may be read
post: returns true if we've reached the end of the file

o eoln
 public boolean eoln()
See if we're at the end of the line.
pre: (none)
post: if no input has been read, input may be read
post: returns true if we're currently at the end of the line

o getErrorDouble
 public double getErrorDouble()
Get the double used to report errors.
pre: (none)
post: The double currently used to report errors is returned.

o getErrorInt
 public int getErrorInt()
Get the integer used to report errors.
pre: (none)
post: The integer currently used to report errors is returned.

o getErrorString
 public String getErrorString()
Get the string used to report errors.
pre: (none)
post: The string currently used to report errors is returned.

o peek
 public char peek()
Look at the next character in the buffer.
pre: we haven't reached the end of the buffer.
post: the next character to be read is returned.
post: one line of input may be read.

o readChar
 public char readChar()
Read the next character (including whitespace) from the given input. If you are at the end of the line, returns the end of line character.
pre: (none)
post: input may be read

o readDouble
 public double readDouble()
Read a double from the given input. Skips any whitespace up to the double . If the next thing in the input is not a double sets the cursor at the beginning of that thing, but does not read beyond it and returns the default double.
pre: the next input characters are whitespace and those that make up an double.
post: the cursor is after those digits.

o readInt
 public int readInt()
Read an integer from the given input. Skips any whitespace up to the integer. If the next thing in the input is not an integer, sets the cursor at the beginning of that thing, but does not read beyond it and returns the default integer.
pre: the next input characters are whitespace and those that make up an integer (optional sign and some number of digits).
post: the cursor is after those digits.

o readLong
 public long readLong()
Read a long integer from the given input. Skips any whitespace up to the integer. If the next thing in the input is not an integer, sets the cursor at the beginning of that thing, but does not read beyond it and returns the default integer.
pre: the next input characters are whitespace and those that make up an integer (optional sign and some number of digits).
post: the cursor is after those digits.

o readLine
 public String readLine()
Read one line from the given input and return that line without any carriage return or other line-terminating character. If we're at the end of file, return the empty string.
pre: we haven't reached the end of the input.
post: the next line (or partial line, if we're already on a line) is returned.

o readLineDouble
 public double readLineDouble()
Read a double from the current line and then skip to the end of the line.
pre: Not yet at end of file.
pre: The next thing in the input is a double.
post: who knows

o readString
 public String readString()
Read the next nonempty string, skipping any intervening whitespace (including carriage returns).
pre: (none)
post: The next nonempty string is returned.

o setErrorDouble
 public void setErrorDouble(double error)
Set the double used to report errors.
pre: (none)
post: the parameter is returned whenever a double should be returned and an error occurs.

o setErrorInt
 public void setErrorInt(int error)
Set the integer used to report errors.
pre: (none)
post: the parameter is returned whenever an integer should be returned and an error occurs.

o setErrorString
 public void setErrorString(String error)
Set the error string.
pre: (none)
post: the error string is now equal to the parameter.

o skipWhite
 public void skipWhite()
Skip over any whitespace until we reach a non-whitespace character or the end of file.
pre: none
post: the cursor is at the next non-whitespace character of we've reached the end of file.


All Packages  Class Hierarchy  This Package  Previous  Next  Index