abstract class Shape
{
double r, h;
Shape(double r, double h)
{
this.r = r;
this.h = h;
}
abstract double calcArea();
abstract double calcVolume();
}
class Sphere extends Shape
{
Sphere(double r)
{
super(r, 0);
}
double calcArea()
{
return 4*3.14*r*r;
}
double calcVolume()
{
return 4*3.14*Math.pow(r,3)/3;
}
}
class Cone extends Shape
{
Cone(double r, double h)
{
super(r, h);
}
double calcArea()
{
return 3.14*r*(r+Math.sqrt(r*r+h*h));
}
double calcVolume()
{
return 3.14*r*r*h/3;
}
}
class Cylinder extends Shape
{
Cylinder(double r, double h)
{
super(r, h);
}
double calcArea()
{
return 2*3.14*r*(h+r);
}
double calcVolume()
{
return 3.14*r*r*h;
}
}
import java.io.*;
class Calculate_Area_Volume
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Shape shape = null;
double r = 0;
double h = 0;
int ch;
do
{
System.out.print("\n1.Sphere"+"\n2.Cone"+"\n3.Cylinder"+ "\n4.Exit "+"\nEnter your choice : ");
ch = Integer.parseInt(br.readLine());
switch (ch)
{
case 1:
System.out.print("Enter radius of sphere:");
r = Double.parseDouble(br.readLine());
shape = new Sphere(r);
break;
case 2:
System.out.print("Enter radius of Cone:");
r = Double.parseDouble(br.readLine());
System.out.print("Enter height of cone:");
h = Double.parseDouble(br.readLine());
shape = new Cone(r,h);
break;
case 3:
System.out.print("Enter radius of cylinder:");
r = Double.parseDouble(br.readLine());
System.out.print("Enter height of cylinder:");
h = Double.parseDouble(br.readLine());
shape = new Cylinder(r,h);
break;
case 4:
System.exit(0);
}
System.out.println("Area = "+shape.calcArea()+"\nVolume = "+shape.calcVolume());
}
while (ch!=4);
}
}