final double PI = Math.PI;
I understand that you get two points for 'using a constant for the value of \$\pi\$', but generally speaking, I will avoid using names that are the same as the static fields that I will in turn rely on (Math.PI) as it may get ambiguous in larger codebases.
( __ / 6 ) Your code is well documented as outlined in section 1.10 of the text by Y. Daniel Lang.and has javadoc style comments before the class and main method.
@rolfl@rolfl posted an excellent answer to another Java question about two months ago regarding comments and Javadoc, and I feel you should definitely have a read at that for your future assignments. Essentially, comments should explain the why, not the how, and if you can avoid using them through the use of properly-named variables or easy-to-understand code constructs, that is generally the more favored approach outside of academic assignments.
In your case, adding a Javadoc to main() is usually redundant as there's nothing much to explain for this arguably famous method. This brings me to one more thing...
To Infinity And Beyond!
You are probably at the stage where you don't have to use methods or under Object-Oriented Programming (OOP) yet, but I guess there's no harm giving you a glimpse of how your code can be restructured.
Instead of putting all your code within the main() method, you can 'group' lines of your code that work together and independent of the rest. For example, you can extract your calculation for a cube's volume out as the following:
/**
* Calculates the volume of a cube, given the length of a side
* @param length length of the cube's side
* @return the volume of the cube
* @throws {@link IllegalArgumentException} if {@code length} is 0 or less
*/
private static int double getVolumeOfCube(double side) {
if (side <= 0.0)) {
throw new IllegalArgumentException("Length cannot be 0 or less.");
}
return side * side * side;
}
What I have illustrated here is a simple Javadoc example explaining:
- The purpose of this method,
- The arguments of this method,
- The return value of this method, and
- Any possible
Exceptions that can be thrown (e.g. validation errors).
From the signature and body of the method, it is also clear how a single length input is used to calculate the volume. Using this method is easy:
System.out.println("The Volume of your CUBE is : " + getVolumeOfCube(length));
In this case, you can even eliminate the temporary cubeVolume variable.