Page 466 - Cs_withBlue_J_C11_Flipbook
P. 466
{
double radius;
public AreaC(double r)
{
radius=r;
}
public double calarea()
{
return 3.142*radius*radius;
}
}
import Eleven.AreaC;
import java.util.*;
class Shape
{
double height,vol;
void conevol()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter radius of cone");
double r=sc.nextDouble();
AreaC obj=new AreaC(r);
System.out.println("Enter height of cone");
height=sc.nextDouble();
vol=obj.calarea()*height/3;
System.out.println("Volume of cone:"+vol);
}
void cylindervol()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter radius of cylinder");
double r=sc.nextDouble();
AreaC obj=new AreaC(r);
System.out.println("Enter height of cylinder");
height=sc.nextDouble();
vol=obj.calarea()*height;
System.out.println("Volume of cylinder:"+vol);
}
public static void main()
{
Shape sh=new Shape();
sh.conevol();
sh.cylindervol();
}
}
464464 Touchpad Computer Science-XI

