Class Util139

java.lang.Object
  extended by Util139

public class Util139
extends java.lang.Object

This class implements some functions needed in cs139.


Method Summary
static java.lang.String getProgLoc()
          This function returns a string indicating the file, method, and line number of where this method was called.
static java.lang.String getProgLoc(int levelAdjust)
          This function returns a string indicating the file, method, and line number of the place adjustLevel method calls prior to where this method was called.
static int nextRandomInt(int range)
          This function returns a random integer in the range 0 to range-1.
static void printDebug(boolean doDebug, java.lang.String format, java.lang.Object... args)
          This function outputs a debugging message if doDebug is true.
static void printDebug(int stmtDebugLevel, java.lang.String format, java.lang.Object... args)
          This function outputs a debugging message if the program's debug is greater than or equal to stsmtDebugLevel.
static double readDouble(java.util.Scanner stream, java.lang.String prompt)
          This function outputs a prompt to standard output, reads the next line of input from stream, outputs a newline character, and then returns the double value on the line (any input on the line after the double value is ignored).
static int readInt(java.util.Scanner stream, java.lang.String prompt)
          This function outputs a prompt to standard output, reads the next line of input from stream, outputs a newline character, and then returns the int value on the line (any input on the line after the int value is ignored).
static java.lang.String readString(java.util.Scanner stream, java.lang.String prompt)
          This function outputs a prompt to standard output, reads the next line of input from stream, outputs a newline character, and then returns the String value on the line (any input on the line after the String value is ignored).
static boolean readYesNo(java.util.Scanner stream, java.lang.String prompt)
          Method purpose: this function prompts the user for a yes or no input and returns true if the user responds affirmatively, and return false if the user responds negatively.
static void setProgDebugLevel(int level)
          This function sets the program's debug level as used by printDebug
static void setRandomSeed(long seed)
          This function sets the seed for the random number generator implemented in this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setRandomSeed

public static void setRandomSeed(long seed)
This function sets the seed for the random number generator implemented in this class.


nextRandomInt

public static int nextRandomInt(int range)
This function returns a random integer in the range 0 to range-1.

Parameters:
range - Specifies the range of the random number.
Returns:
A random integer between 0 and range-1.

readInt

public static int readInt(java.util.Scanner stream,
                          java.lang.String prompt)
This function outputs a prompt to standard output, reads the next line of input from stream, outputs a newline character, and then returns the int value on the line (any input on the line after the int value is ignored).

Parameters:
stream - A Scanner object input is read from
prompt - The prompt string.
Returns:
The value you read

readDouble

public static double readDouble(java.util.Scanner stream,
                                java.lang.String prompt)
This function outputs a prompt to standard output, reads the next line of input from stream, outputs a newline character, and then returns the double value on the line (any input on the line after the double value is ignored).

Parameters:
stream - A Scanner object input is read from
prompt - The prompt string.
Returns:
The value you read

readString

public static java.lang.String readString(java.util.Scanner stream,
                                          java.lang.String prompt)
This function outputs a prompt to standard output, reads the next line of input from stream, outputs a newline character, and then returns the String value on the line (any input on the line after the String value is ignored).

Parameters:
stream - A Scanner object input is read from
prompt - The prompt string.
Returns:
The value you read

readYesNo

public static boolean readYesNo(java.util.Scanner stream,
                                java.lang.String prompt)
Method purpose: this function prompts the user for a yes or no input and returns true if the user responds affirmatively, and return false if the user responds negatively. A response of "yes" or "y" (case ignored) as an affirmative response, a response of "no" or "n" (case ignored) as a negative response. Any other response will cause the function to ask the question again.

Parameters:
stream - Input stream the input is to be read from.
prompt - The prompt output before trying to read.
Returns:
A boolean indicating if the user responded affirmatively.

setProgDebugLevel

public static void setProgDebugLevel(int level)
This function sets the program's debug level as used by printDebug

Parameters:
level - Value the program's debug level gets set to

printDebug

public static void printDebug(boolean doDebug,
                              java.lang.String format,
                              java.lang.Object... args)
This function outputs a debugging message if doDebug is true. The debugging message indicates the location in the program where this method was called, following by the output generated from the "printf" format string and the arguments that following it. If the format string is just "\n", just the program location is printed.

Parameters:
doDebug - Boolean indicating whether or not to print the debug statements
format - The printf style format string
args - The arguments used by the format string

printDebug

public static void printDebug(int stmtDebugLevel,
                              java.lang.String format,
                              java.lang.Object... args)
This function outputs a debugging message if the program's debug is greater than or equal to stsmtDebugLevel. The debugging message indicate the location in the program where this method was called, following by the output generated from the "printf" format string and the arguments that following it. If the format string is just "\n", just the program location is printed.

Parameters:
stmtDebugLevel - The debugging of level of this print statement
format - The printf style format string
args - The arguments used by the format string

getProgLoc

public static java.lang.String getProgLoc(int levelAdjust)
This function returns a string indicating the file, method, and line number of the place adjustLevel method calls prior to where this method was called.

Parameters:
levelAdjust - An integer indicating how far up the stack to find the location
Returns:
A string indicating the location in the program where this function was called from.

getProgLoc

public static java.lang.String getProgLoc()
This function returns a string indicating the file, method, and line number of where this method was called.

Returns:
A string indicating the location in the program where this function was called from.