>>106002704public class Test {
public static void main(String[] args) {
Prism prism1 = new Prism(10, 3, 7);
Prism prism2 = new Prism(3, 7, 10);
System.out.println("cube 1: " + prism1);
System.out.println("cube 2: " + prism2);
if (prism1.fitsInsideOf(prism2)) {
System.out.println("cube 1 fits inside of cube 2 in the same position");
} else if (prism1.rotatedAlongLengthAxis().fitsInsideOf(prism2)) {
System.out.println("cube 1 fits inside of cube 2 after being rotated along the length axis");
} else if (prism1.rotatedAlongWidthAxis().fitsInsideOf(prism2)) {
System.out.println("cube 1 fits inside of cube 2 after being rotated along the width axis");
} else if (prism1.rotatedAlongHeightAxis().fitsInsideOf(prism2)) {
System.out.println("cube 1 fits inside of cube 2 after being rotated along the height axis");
} else if (prism1.rotatedAlongLengthAxis().rotatedAlongHeightAxis().fitsInsideOf(prism2)) {
System.out.println("cube 1 fits inside of cube 2 after being rotated along the length axis, then the width axis");
} else if (prism1.rotatedAlongHeightAxis().rotatedAlongLengthAxis().fitsInsideOf(prism2)) {
System.out.println("cube 1 fits inside of cube 2 after being rotated along the height axis, then the length axis");
} else {
System.out.println("Cube 1 does not fit inside of cube 2");
}
}
}
class Prism {
final float l, w, h;
public Prism(float l, float w, float h) {
this.l = l;
this.w = w;
this.h = h;
}
public Prism rotatedAlongLengthAxis() {
return new Prism(l, h, w);
}
public Prism rotatedAlongWidthAxis() {
return new Prism(h, w, l);
}
public Prism rotatedAlongHeightAxis() {
return new Prism(w, l, h);
}
public boolean fitsInsideOf(Prism other) {
return this.l <= other.l && this.w <= other.w && this.h <= other.h;
}
@Override
public String toString() {
return "Length: " + l + "cm, Width: " + w + "cm, Height: " + h + "cm";
}
}
have some OOP