여기 내 자바 문제가 Shape 인터페이스의 (의 Rectangle2D r에) 메소드가 포함되어 있습니다. boolean contains (Rectangle2D r)의 "Shape의 내부가 지정된 Rectangle2D를 완전하게 포함하고 있을지 어떨지를 테스트합니다."라는 문제가 있습니다. 이제 Rectangle2D는 사각형의 모서리 좌표를 가져 오는 메서드를 제공하지 않는 추상 클래스입니다. 보다 정확하게는, "Rectangle2D 클래스는 위치 (x, y)와 크기 (wxh)로 정의되는 사각형을 기술합니다.이 클래스는 2D 사각형을 저장하는 모든 객체의 추상 수퍼 클래스입니다. 하위 클래스에 남겨 둡니다. "구현 부울
어떻게 해결할 수 있습니까?
내 코드의 일부를 검색 :
public class Circle implements Shape
{
private double x, y, radius;
public Circle(double x, double y, double radius)
{
this.x = x;
this.y = y;
this.radius = radius;
}
// Tests if the specified coordinates are inside the boundary of the Shape
public boolean contains(double x, double y)
{
if (Math.pow(this.x-x, 2)+Math.pow(this.y-y, 2) < Math.pow(radius, 2))
{
return true;
}
else
{
return false;
}
}
// Tests if the interior of the Shape entirely contains the specified rectangular area
public boolean contains(double x, double y, double w, double h)
{
if (this.contains(x, y) && this.contains(x+w, y) && this.contains(x+w, y+h) && this.contains(x, y+h))
{
return true;
}
else
{
return false;
}
}
// Tests if a specified Point2D is inside the boundary of the Shape
public boolean contains(Point2D p)
{
if (this.contains(p.getX(), p.getY()))
{
return true;
}
else
{
return false;
}
}
// Tests if the interior of the Shape entirely contains the specified Rectangle2D
public boolean contains(Rectangle2D r)
{
// WHAT DO I DO HERE????
}
}
이 숙제입니까? 그러나 태그 슬롯이 남아 있지 않습니다 ... –
어떤 개발 환경을 사용하고 있습니까? 특정 클래스에 대한 지식 부족이 문제가되지 않아야하기 때문에 'r'을 입력 할 때'r '의 사용 가능한 메소드를 보여 주어야합니다. – weston