0

我的老师要我找到我创建的 2 个矩形之间的交点。请帮我弄清楚为什么这不运行。我得到的错误说找不到变量底部。

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;
    }
4

1 回答 1

1

因为在顶部你写了:

bottem = b;

不是底部。

下次尝试通过正确格式化代码来更轻松地帮助您。

于 2013-04-22T19:38:40.590 回答