It's quite easy, you're missing something here:
volume.getVolume()
should be volume[i].getVolume()
volume
is the array, while volume[i]
is an instance of your Cylinder
class.
As a side note, instead of defining PI in a constant, you can use Math.PI
which is already defined (and more accurate).
Updated answer:
In your Cylinder class, you are initializing the volume
variable to 0. I suggest you remove the volume
variable and the getVolume
method. And instead of calling the getVolume
method you should call the volume()
method. Computing the volume is very fast, you don't need to store it as a variable in the class.