1.[文件] Cylinder.java ~ 1014B 下载(18)
/**
* Cylinder.java
*/
public class Cylinder implements SolidGraphics2 {
Circle c;
double height;
public Cylinder(Circle ce,double h) {
c=ce;
height=h;
}
public double area(){
return 2 * c.area()+
c.perimeter()*height;
}
public double volume(){
return c.area()*height;
}
public String toString(){
return c.toString() +"; 圆锥高为 = "+height;
}
public static void main(String args[])
{
Circle c1=new Circle(7);
Cylinder cy1=new Cylinder(c1,15);
System.out.println("该圆锥的相关信息:"+cy1.toString());
System.out.println("该圆锥表面积为:"+cy1.area());
System.out.println("该圆锥体积为:"+cy1.volume());
Point p=new Point(34.5f,23);
Circle c2=new Circle(p,7);
Cylinder cy2=new Cylinder(c2,15);
System.out.println("该圆锥的相关信息:"+cy2.toString());
System.out.println("该圆锥表面积为:"+cy2.area());
System.out.println("该圆锥体积为:"+cy2.volume());
}
}