首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型xxx中的方法xxx不适用于参数()

类型xxx中的方法xxx不适用于参数()
EN

Stack Overflow用户
提问于 2021-06-23 15:48:06
回答 1查看 195关注 0票数 1

我对java很陌生,我正在尝试用建筑类和城市类来做一个城市规划项目。当试图在城市类中为addStructure构建一个方法时,我得到了一个错误:“类型构建中的方法addStructure不适用于参数()”,该方法根据构建类中方法isValidPlacement中的条件返回true或false基。我不知道为什么,也不知道怎么解决。

代码语言:javascript
复制
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方法检查两个条件:如果建筑物在城市范围内,以及建筑物是否与现有建筑物重叠。

代码语言:javascript
复制
    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语句。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-24 03:45:09

在这条线上-

代码语言:javascript
复制
if (Building.isValidPlacement() == false) { 
    // Error: The method isValidPlacement in the type Building is 
       not applicable for arguments()
        return false;
}

  • 调用isValidPlacement方法时不带任何参数,尽管该方法包含参数。传入指定的参数以修复错误.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68103177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档