
/**
 * demonstration of abstract classes
 */

public abstract class Solid
    {
    public abstract double surfaceArea() ;

    public abstract double volume() ;
    } // end of class Solid

class Sphere extends Solid
    {
    private double radius ;

    public Sphere()
	{
	radius = 0.0 ;
	} // end of constructor method

    public Sphere(double r)
	{
	radius = r ;
	} // end of constructor method

    public double volume()
	{
	return 4.0/3.0 * Math.PI * radius * radius * radius ;
	} // end of method volume

    public double surfaceArea()
	{
	return 4 * Math.PI * radius * radius ;
	} // end of method surfaceArea

    public String toString()
	{
	return "Sphere radius " + radius + " surface area " + surfaceArea()
		+ " volume " + volume() ;
	} // end of method toString
    } // end of class Sphere

class Cuboid extends Solid
    {
    private double height, breadth, length ;

    public Cuboid()
	{
	length = 0.0 ;
	breadth = 0.0 ;
	height = 0.0 ;
	} // end of constructor method

    public Cuboid(double l, double b, double h)
	{
	length = l ;
	breadth = b ;
	height = h ;
	} // end of constructor method

    public double volume()
	{
	return length * breadth * height ;
	} // end of method volume

    public double surfaceArea()
	{
	return (2 * length * breadth) + (2 * length * height)
		+ (2 * breadth * height) ;
	} // end of method surfaceArea

    public String toString()
	{
	return "Cuboid length " + length +
		" breadth " + breadth +
		" height " + height +
		" surface area " + surfaceArea() +
		" volume " + volume() ;
	} // end of method toString
    } // end of class Cuboid

class Cylinder extends Solid
    {
    private double height, radius ;

    public Cylinder()
	{
	radius = 0.0 ;
	height = 0.0 ;
	} // end of constructor method

    public Cylinder(double r, double h)
	{
	radius = r ;
	height = h ;
	} // end of constructor method

    public double volume()
	{
	return Math.PI * radius * radius * height ;
	} // end of method volume

    public double surfaceArea()
	{
	return (2 * Math.PI * radius * radius) +
		(2 * Math.PI * radius * height) ;
	} // end of method surfaceArea

    public String toString()
	{
	return "Cylinder height " + height + " radius " + radius +
		" surface area " + surfaceArea() +
		" volume " + volume() ;
	} // end of method toString	
    } // end of class Cylinder


