See below
Because the instance variables are private
,
you need methods to return their values.
The methods are made public
so that they can be used by other classes.
A method that returns a value from an instance variable is called an access method or a getter.
Their name often begins with "get".
// file: Cone.java // public class Cone { private double radius; // radius of the base private double height; // height of the cone public Cone( double radius, double height ) { this.radius = radius; this.height = height; } public double area() { return Math.PI*radius*(radius + Math.sqrt(height*height + radius*radius) ); } public double volume() { return Math.PI*radius*radius*height/3.0; } public void setHeight( double height ) { if ( height >= 0 ) this.height = height ; } public void setRadius( double radius ) { if ( radius >= 0 ) this.radius = radius ; } public getHeight( ) { return ( ) ; } public getRadius( ) { return ( ) ; } }
Fill in the blanks