Question: 5. (10 pts) You are given the class Box, below, that is defined to implement the interface Comparable . Provide the implementation of the
5. (10 pts) You are given the class Box, below, that is defined to implement the interface Comparable . Provide the implementation of the compareTo() method such that a Box with smaller volume is con- sidered less than a Box with greater volume (e.g., smaller boxes would come first if they were sorted using Arrays.sort()). class Box implements Comparable { private int width, height, depth; public Box (int w, int h, int d) { width = W; height = h; depth = d; } public int getWidth () { return width; } public int getHeight () { return height; } public int getDepth () { return depth; } public int compare To (Object other) {
Step by Step Solution
3.41 Rating (164 Votes )
There are 3 Steps involved in it
5 class Box implements Comparable attributes private int width height depth 3arg... View full answer
Get step-by-step solutions from verified subject matter experts
