Start New Discussion within our Software Development Community

Hi Am working on s shape inheritance hierarchy project where we are supposed to define 2d or 3d shapes then use a few examples e.g circles or spheres to calculate areas and volumes of the 2d and 3d shapes respectively. Everything is working fine it compiles and builds successfully but I am unable to calculate the area and the volume of the 3d objects could someone please help? here is my code

// Exerciae 10.9: SphereShape.java
// Sphere Shape class extends ThreeDimensionalShape.

public class SphereShape extends ThreeDimensionalShape
{
   private double radius; // sphere radius

   // constructor
   public SphereShape(double radius )
   {
      super("SphereShape");
	  this.radius = radius;

        @SuppressWarnings("LocalVariableHidesMemberVariable")
      double volume = ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius, 3 );

    // end method sphereVolume


        @SuppressWarnings("LocalVariableHidesMemberVariable")
      double area = 4 * Math.PI * (radius*radius);

    // end method sphereVolume
   } // end constructor

  // return String representation of Sphere object

   public String toString()
   {
      return String.format( "This is a sphere. It's radius = %f. It's volume = %f\n", radius, volume);

} // end method toString
} // end class SphereShape

I have attached the whole project if you need to reference other classes.

Lines 14,15 and 20,21.
LocalVariableHidesMemberVariable !
result totally counterproductive

This question has already been answered. Start a new discussion instead.