我在Java课上做了一个家庭作业项目,我有一个问题。我有两个班:
Robot
获取构造函数中的参数并初始化其某些属性。
我想在构造函数中将创建的Robot
对象添加到Robot的二维数组中,但我不确定如何。
public class Robot {
char name;
Grid grid;
int row;
int col;
int energyUnits;
String task;
int destRow;
int destCol;
Robot r;
Robot[][] roboArr = new Robot[row][col];
/**
* Construct a robot and place it in the grid.
*
* @param name
* @param grid
* @param row
* @param col
* @param energyUnits
*/
public Robot(char name, Grid grid, int row, int col, int energyUnits) {
this.name = name;
this.grid = grid;
this.row = row;
this.col = col;
this.energyUnits = energyUnits;
roboArr = grid.getRoboArr();
roboArr[row - 1][col - 1] = r;
}
}