2013-04-22 2 views
0

선생님은 내가 만든 두 개의 사각형 사이의 교차점을 찾길 원합니다. 왜 이것이 실행되지 않는지 알아 내도록 도와주세요. 내가 말한 오류는 가변 하단을 찾을 수 없습니다.사각형 자바 교차점

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; 
    } 
+1

'bottem'은'bottom'과 같은 것이 아닙니다. –

+0

무료로 당신을 도울 것을 요청하는 사람들에게 예의를 보이고 코드를 읽기 쉽게하십시오. – djechlin

+0

오, 쓰레기 철자 오류 : P –

답변

1

은 상단에 당신이 쓴 때문에 :

bottem = b; 

하지 바닥을.

다음 번에 코드의 형식을 올바르게 지정하면 도움이 될 것입니다.

+0

thanks :) 죄송합니다. 읽기가 어렵습니다. Mac에서이 작업을 시도하고 있으며 형식을 지정하기가 정말 어렵습니다. 내 프로그램에서는 괜찮 았지만 여기에 붙여 넣을 때 형식이 변경되었습니다. –