Class ArrayChange

java.lang.Object
   |
   +----ArrayChange

public class ArrayChange
extends Object
ArrayChange instantiates an array of integer values that can be changed by selecting one of its members and supplying a new value for the selected element. Changes the value of the selected element, of all neighboring elements of equal value, and so on for neighbors of the neighbors. Example:

java ArrayChange 7 4 4 
3  2  1  3  3  3  3
1  2  4  1  4  1  4
2  3  4  3  2  1  4
2  1  4  4  3  2  4
Select coordinate to zero (col row): 3 3
3  2  1  3  3  3  3
1  2  0  1  4  1  4
2  3  0  3  2  1  4
2  1  0  0  3  2  4
Select coordinate to zero (col row):
 
A 7 x 4 array of values ranging from 1 through 4 was requested. User chose to zero the "4" at column 3, row 3. Three adjoining/connected "4"s were automatically zeroed as well.

Author:
Tony Dahlman

Variable Index

 o array
Two dimensional array of ArrayPoint objects.
 o colMax
 o cols
 o rowMax
 o rows

Constructor Index

 o ArrayChange(int, int, int)
Constructor sets number of rows and columns in the array of ArrayPoint objects, then randomly sets their values to be anything from 1 to the specified maximum value.

Method Index

 o conPrint(String)
Returns this 2D array as columns & rows (monospaced) of values.
 o flood(ArrayPoint, int)
Given a point in the array, flood() first gets a list of adjacent points with equal value, then sets a new value for itself, and finally, it recursively calls itself to handle the list of neighboring points.
 o getRandomInt(int, int, Random)
Utility method to generate a random positive integer within a specified (inclusive) range.
 o getStartPoint(String)
Parses input, converting the string to two single-digit integers corresponding to the column/row coordinates of an ArrayPoint object.
 o main(String[])
Command line test code for ArrayChange and its recursive flood() method.

Variables

 o array
 private ArrayPoint array[][]
Two dimensional array of ArrayPoint objects.

 o cols
 private static int cols
 o rows
 private static int rows
 o colMax
 private static int colMax
 o rowMax
 private static int rowMax

Constructors

 o ArrayChange
 public ArrayChange(int rows,
                    int cols,
                    int maxValue)
Constructor sets number of rows and columns in the array of ArrayPoint objects, then randomly sets their values to be anything from 1 to the specified maximum value.

Methods

 o getRandomInt
 static int getRandomInt(int low,
                         int high,
                         Random r)
Utility method to generate a random positive integer within a specified (inclusive) range.

 o conPrint
 String conPrint(String sep)
Returns this 2D array as columns & rows (monospaced) of values. Use code page 850.

Parameters:
sep - platform specific EOL string usually obtained with System.getProperty();
 o getStartPoint
 ArrayPoint getStartPoint(String s)
Parses input, converting the string to two single-digit integers corresponding to the column/row coordinates of an ArrayPoint object.

Returns:
the ArrayPoint object, if possible.
 o flood
 synchronized void flood(ArrayPoint start,
                         int newVal)
Given a point in the array, flood() first gets a list of adjacent points with equal value, then sets a new value for itself, and finally, it recursively calls itself to handle the list of neighboring points. Synchronized so value changes can complete before being checked by other recursive passes through this method.

Parameters:
start - an ArrayPoint object
newVal - the int value to which this ArrayPoint will be set
 o main
 public static void main(String args[]) throws IOException
Command line test code for ArrayChange and its recursive flood() method. Supply two integer arguments to set the number of columns and rows of the array. Supply a third integer to specify the range of values (1 thru n) each element of the array can hold.