Use the reserved word this to
show when an identifier refers to an object's instance variable.
public class Cone
{
// instance variables
private double radius; // radius of the base
private double height; // height of the cone
// constructor
public Cone( double radius, double height )
{
this.radius = radius;
this.height = height;
}
// methods
public double volume()
{
return ;
}
public double area()
{
return ;
}
}
Here is the syntax for method definition:
modifiers returnType methodName ( parameterList )
{
statementList
}
The first line in the above is called the header of a method.
It does not have to be all on one line.
The returnType is the data type that the method returns.
It will be one of the primitive data types, or a class.
The methodName is an identifier picked by the programmer.
It can be any identifier except for reserved words or identifiers already in use.
The parameterList is a list of parameters and their data types.
If there are no parameters, the parameter list is omitted,
(but the two parentheses must be there).
The signature of a method is the methodName and parameterList.
Now complete the volume() method by filling in the blank.
The formula for volume is:
V = π*r2*h/3
The formula for surface area (including the base) is:
A = π*r*( r + √(h2 + r2) )
Fill in the blanks
You will need to a static constant and method of the Math class.