You would expect to use:
Any other attributes of a cone can be calculated from these two.
Cone
class
Object oriented design means deciding what classes you need,
what data the objects hold,
and how the objects will behave.
Let us do that with the Coner
class.
ConeA class that represents right circular cones
Variables
private double height; // height of the cone
private double radius; // radius of the circular base
Constructors
public Cone( double radius, double height )
Creates a new instance of a Cone object with the specified height and radiusMethods
public double area()
calculates and returns the area of the conepublic double volume()
calculates and returns the volume of the conepublic void setHeight()
changes the height of a conepublic void setRadius()
changes the radius of a conepublic double getHeight()
returns the height of a conepublic double getRadius()
returns the radius of a cone
Instance variables (like height
) are usually made private
so
that only the constructors and methods of the object may access them.
The set
methods may be used to change the values in selected instance variables
and get
methods may be used to access the values.
(More on this later.)
Constructors are usually made public
.
Make public
methods that are to be used outside of the object.
(For now, all our methods.)
Could a main()
method create a Cone
object?