Loading...
Loading...
A courier office measures parcel boxes. Most boxes have three sides, but a cube is entered with just one number. For each box print its volume and its surface area (for the wrapping paper), and mark cubes.
Write a class Box with fields length, width and height, a constructor Box(long length, long width, long height) and a second constructor Box(long side) that calls the first with this(...). Add long volume(), long surfaceArea() and boolean isCube().
volume surfaceArea, followed by CUBE when all three sides are equal.Example
Input
2 2 3 4 5
Output
24 52 125 150 CUBE
The second box is given by one side, so it is a 5 × 5 × 5 cube.
Try the problem first. Open one hint at a time.
The one-side constructor has a single line: pass the side three times to the three-side constructor.
Surface area is 2 × (lw + wh + hl).
Read each line with nextLine() and split it; the number of parts tells you which constructor to call.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor