SodaCan Class
//Kevin
/**
*A can has a height and radius.
*/
public class SodaCan
{
public double height;
public double radius;
/**
*Creates a soda can with a height and radius.
*@param newHeight Specifies the height.
*@param newRadius Specifies the radius.
*/
public SodaCan(double newHeight, double newRadius)
{
height=newHeight;
radius=newRadius;
}
/**
*Calculates and returns the surface area.
*@return Returns surface area.
*/
public double getSurfaceArea()
{
return 2*(22/7.0)*radius*radius+2*(22/7)*radius*height;
}
/**
*Calculates and Returns the volume.
*@return Returns volume.
*/
public double getVolume()
{
return (22/7.0)*radius*2*height;
}
/**
*Displays all of the data.
*@return Returns all data.
*/
public String toString()
{
return "Height: "+height+"\n"+
"Radius: "+radius+"\n"+
"Surface Area: "+getSurfaceArea()+"\n"+
"Volume: "+getVolume();
}
}
/** OUTPUT FROM DEMO
Height: 12.0
Radius: 5.0
Surface Area: 517.1428571428571
Volume: 377.1428571428571
Press any key to continue...
*/
Home