中的isnesting方法 Box
负责检查一个长方体示例是否完全嵌套在另一个长方体示例中,方法是检查每个维度是否在父长方体的边界内。返回true的示例。返回false的示例。
class Box {
private float width;
private float height;
private float length;
Box(float width, float height, float length) {
this.width = width;
this.height = height;
this.length = length;
}
public boolean isNesting(Box outsideBox) {
if(this.length <= outsideBox.length && this.width <= outsideBox.width && this.height <= outsideBox.height)
return true;
return false;
}
public Box biggerBox(Box oldBox) {
return new Box(1.25f*oldBox.getWidth(), 1.25f*oldBox.getHeight(), 1.25f*oldBox.getLength());
}
public Box smallerBox(Box oldBox) {
return new Box(.25f*oldBox.getWidth(), .25f*oldBox.getHeight(), .25f*oldBox.getLength());
}
}
但是,这里的问题是,这种方法不包括smallerbox或basebox可能具有的不同旋转。我该如何整合这个逻辑?
class BoxTester {
public static void main(String[] args){
Box baseBox = new Box(2.5f, 5.0f, 6.0f);
Box biggerBox = baseBox.biggerBox(baseBox);
Box smallerBox = baseBox.smallerBox(baseBox);
System.out.println(baseBox.isNesting(smallerBox));
}
}
1条答案
按热度按时间0s0u357o1#
对两个长方体的尺寸进行排序。
按顺序比较相应的尺寸。