我对java很陌生,我正在尝试用建筑类和城市类来做一个城市规划项目。当试图在城市类中为addStructure构建一个方法时,我得到了一个错误:“类型构建中的方法addStructure不适用于参数()”,该方法根据构建类中方法isValidPlacement中的条件返回true或false基。我不知道为什么,也不知道怎么解决。
public boolean addStructure(int x, int y, Building structure) {
// x & y are new postions
// Structure is a building object called from building constructor
int posx = x;
int posy = y;
int w = structure.getWidth();//Building width
int l = structure.getLength();//Building length
int layw = layout[0].length;// City width (Building type 2d array Building[][] layout
int layl = layout.length;// City length
String sign = structure.toString();
if (Building.isValidPlacement() == false) { // Error: The method isValidPlacement in the type Building is not applicable for arguments()
return false;
} else {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
layout[i][j] = new Building(sign,x,y);
}
}
}
}IsValidPlacement方法检查两个条件:如果建筑物在城市范围内,以及建筑物是否与现有建筑物重叠。
public boolean isValidPlacement(Building[][] layout,int x, int y) { //example 2x2
//x and y are position of the building where we wish to plant
// call for the get width function to compare
int w = getWidth();
int l = getLength();
int layw = layout[0].length;
int layl = layout.length;
//step 1 check for within city
if (x<0 || x+w > layw) { // check if x is outside of range
return false;
} else if (y < 0 || y+l > layl) { //Check if y is outside of range
return false;
} // If the above cond. all passed then check if overlap.
for (int i = x; i < x+w ; ) {
for (int j = y; j < y+l;) {
if (layout[i][j] != null) {
return false;}
}
} return true;
}这两个函数都应该返回true或false语句。
发布于 2021-06-24 03:45:09
在这条线上-
if (Building.isValidPlacement() == false) {
// Error: The method isValidPlacement in the type Building is
not applicable for arguments()
return false;
}https://stackoverflow.com/questions/68103177
复制相似问题