Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
矩形java的交集_Java_Intersection - Fatal编程技术网

矩形java的交集

矩形java的交集,java,intersection,Java,Intersection,我的老师想让我找到我创建的两个矩形之间的交点。请帮我弄清楚为什么这个不能运行。我得到的错误是找不到变量bottom public class Rectangle { private int left, bottem, width, height; public Rectangle (int l, int b, int w, int h) { left = l; bottem = b; width = w; he

我的老师想让我找到我创建的两个矩形之间的交点。请帮我弄清楚为什么这个不能运行。我得到的错误是找不到变量bottom

public class Rectangle { 

    private int left, bottem, width, height;

    public Rectangle (int l, int b, int w, int h) {
        left = l;
        bottem = b;
        width = w;
        height = h;   
    }

    public int getX() {
        return left;
    }

    public int getY() {
         return bottem;
    }

    public int getW() {
         return width;
    }

    public int getH() {
         return height;
    }

    public int getArea () {
        int area;
        area = (width * height);
        return area;
    }

    public int getPerimeter() {
        int perimeter;
        perimeter = (width + height) * 2;
        return perimeter;
    }

    public int getIntersection (Rectangle one, Rectangle two)  {
         int intxValue;
         int intyValue;
         int intxValue2;
         int intyValue2;
         int area;

         if (one.left + one.width > two.left && one.bottom + one.height > two.bottom) {
               intxValue = two.left;
               intyValue = two.bottom;
               intxValue2 = one.left + one.width - intxValue;
               intyValue2 = one.bottom + one.height - intyValue;
               area = intxValue2*intyValue2;
               return area;
         } else if (one.left+one.width < two.left && one.bottom+one.height < two.bottom) {
               intxValue = one.left;
               intyValue = one.bottom;
               intxValue2 = two.left + two.width - intxValue;
               intyValue2 = two. bottom + two.height - intyValue;
               area = intxValue2*intyValue2;
               return area;
         } else return area;
    }
公共类矩形{
私有int左、右、宽、高;
公共矩形(整数l、整数b、整数w、整数h){
左=l;
bottem=b;
宽度=w;
高度=h;
}
公共int getX(){
左转;
}
公共int getY(){
返回bottem;
}
公共int getW(){
返回宽度;
}
公共int getH(){
返回高度;
}
公共区域(){
内部区域;
面积=(宽度*高度);
返回区;
}
公共int getpermiture(){
周长;
周长=(宽度+高度)*2;
返回周长;
}
公共int getIntersection(矩形一,矩形二){
int intxValue;
int intyValue;
int intxValue2;
int intyvalue 2;
内部区域;
如果(1.left+1.width>2.left&&1.bottom+1.height>2.bottom){
intxValue=2.left;
intyValue=2.bottom;
intxValue2=1.left+1.width-intxValue;
intyValue2=1.bottom+1.height-intyValue2;
面积=intxValue2*intyValue2;
返回区;
}else if(1.left+1.width<2.left&&1.bottom+1.height<2.bottom){
intxValue=1.left;
intyValue=1.bottom;
intxValue2=2.left+2.width-intxValue;
intyValue 2=2.bottom+2.height-intyValue;
面积=intxValue2*intyValue2;
返回区;
}其他返回区;
}

因为您在顶部写了:

bottem = b;
不是底部


下次尝试通过正确设置代码的格式来帮助您。bottem

bottem
bottom
不是一回事。请对您要求免费帮助您的人表示一些礼貌,使您的代码易于阅读。哦,废话-哈哈,拼写错误:P@djechlin对不起,它在我的电脑上看起来很好,但是当我粘贴它的时候在这里,它改变了格式,我在我的mac电脑上很难改变格式。我对我对代码外观的无知表示歉意。这是我高中的第一年,我还在学习。谢谢:)对不起,很难阅读,我正试图在mac电脑上做这件事,而且很难格式化。在我的程序中,这很好,但当我粘贴它时在格式改变之前。