0
我的老師讓我找到我創建的兩個矩形之間的交集。請幫我弄清楚爲什麼這個不運行。我得到的錯誤說找不到變量底部。矩形的交叉點java
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;
}
'bottem'與'bottom'不是一回事。 – 2013-04-22 19:38:28
請向您要求幫助您的人免費贈送禮物,並讓您的代碼易於閱讀。 – djechlin 2013-04-22 19:38:37
哦,廢話哈哈拼寫錯誤:P – 2013-04-22 19:39:23