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 )
	  this.radius = radius;

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

    // end method sphereVolume

      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.

6 Years
Discussion Span
Last Post by quuba

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.