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
-
array
- Two dimensional array of ArrayPoint objects.
-
colMax
-
-
cols
-
-
rowMax
-
-
rows
-
-
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.
-
conPrint(String)
-
Returns this 2D array as columns & rows (monospaced) of values.
-
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.
-
getRandomInt(int, int, Random)
-
Utility method to generate a random positive integer within a specified
(inclusive) range.
-
getStartPoint(String)
- Parses input, converting the string to two single-digit integers
corresponding to the column/row coordinates of
an ArrayPoint object.
-
main(String[])
- Command line test code for ArrayChange and its recursive
flood() method.
array
private ArrayPoint array[][]
- Two dimensional array of ArrayPoint objects.
cols
private static int cols
rows
private static int rows
colMax
private static int colMax
rowMax
private static int rowMax
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.
getRandomInt
static int getRandomInt(int low,
int high,
Random r)
- Utility method to generate a random positive integer within a specified
(inclusive) range.
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();
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.
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
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.