Hello!!
I have been trying to figure out the syntax to create a method that will subdivide a GridCell object.
The GridCells display in the main program in a 2-D grid.
In the main program I want to be able to loop thru the grid, select a GridCell, and divide that cell into 4 new smaller cells.
I have picked up some info via Coding Train, stack overflow, and myriad other sites. However reaching a point in the code below.
I have read/watched content that discusses passing a reference vs passing a value, in addition to methods that return arrayLists. I think this will somehow affect how to write the syntax but am not sure how to integrate this into the code.
Additionally, since a function can only return a single value/reference—and I need to return 4 separate values/referneces—I have placed 4 functions (one for each value to be returned) into a function that would return an ArrayLIst of the 4 values returned. Is this a valid approach?
The syntax(and maybe even the logic) below is probably laughably wrong…but hopefully it illustrates the intent.
Any guidance is gratefully appreciated.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class GridCell{
// variables & constructor of a simple GridCell w/ x, y, w, h coordinates...
void display(){
// rect(x, y, w, h);
}
//** here is the question: **
//** I know this syntax is not correct **
public ArrayList subdivide (Arraylist GridCell smCell) {
GridCell topLeft() {
return new GridCell(smCell.x, smCell.y, w/2, h/2);
}
GridCell topRight() {
return new GridCell(smCell.x+w/2, smCell.y, w/2, h/2);
}
GridCell lowerLeft() {
return new GridCell(smCell.x, smCell.y+h/2, w/2, h/2);
}
GridCell lowerRight() {
return new GridCell(smCell.x+w/2, smCell.y+h/2, w/2, h/2);
}
return ArrayList GridCell smCell;
}