My orchard is arranged in a square, with the rows and columns numbered 1, 2,
..., n. I need software to choose the location where the
next tree should be planted.
I want the next tree not to be interfered with by existing trees or by the
activities of the neighboring landowners. Therefore, I want to
choose the location for which the shortest orthogonal path that goes either to a tree or
out of the orchard is as
long as possible. By an orthogonal path I mean a sequence of steps that go
along rows and/or columns (not diagonally). If there are several locations that have
the same shortest orthogonal path, break the tie by choosing the smallest
row number, and, if necessary, break any remaining tie by choosing the smallest
The existing layout of the orchard is shown by a String orchard in which the
elements correspond to rows 1, 2, ..., n. Within each element of orchard, the
characters correspond to columns 1, 2, ..., n. The character 'T' indicates an existing
tree at that row and column, while '-' indicates an available location.
Create a class Orchard that contains a
method nextTree that is given a String orchard and returns
a int with two
elements giving the row and column of the chosen location. The first element of
the return should give the row, and the second element should give the column.