Something like this is probably what you are looking for. Not sure about the correctness of the program as I'm not familiar with GridWorld or the other objects in your code.
The basics are however the double loop, looping over each row and for each row looping over the column thus covering the whole grid.
As you can see I left the isFlowerAt
method empty since I have no idea what grid.get()
will return.
int counter = 0;
for (int row = 0; row < grid.getNumRows(); row++) {
for (int col = 0; col < grid.getNumCols(); col++) {
if (isFlowerAt(grid, row, col)){
counter++;
}
}
}
return counter;
private boolean isFlowerAt(Grid grid, int row, int col) {
//Return true if a flower is located at (row, col)
}