我的老师要我找到我创建的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;
}
答案 0 :(得分:1)
因为在最上面你写了:
bottem = b;
不是BottOm。
下次尝试通过正确格式化代码来更轻松地帮助您。