-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.java
36 lines (28 loc) · 707 Bytes
/
box.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.*;
class box implements Comparable <box> {
public final String name;
public final Float d[] = new Float[3]; //dimensions
public final double volume;
public box(String name, float d1, float d2, float d3) {
this.name = name;
d[0] = d1;
d[1] = d2;
d[2] = d3;
Arrays.sort(d, Collections.reverseOrder());
volume = d1 * d2 * d3;
}
public int compareTo(box x) {
return Double.valueOf(volume).compareTo(x.volume);
}
//this box can contain that box
public boolean canHas(box x) {
if (d[0] > x.d[0] && d[1] > x.d[1] && d[2] > x.d[2]) {
assert volume > x.volume;
return true;
}
//else if (d[0] < x.d[0] && d[1] < x.d[1] && d[2] < x.d[2])
// return -1;
else
return false;
}
}