求圆锥体积

class Circle{
 private double radius;
 
 Circle(double r){
  radius=r;
 }
 
 public void setRadius(double r){
  radius=r;
 }
 public double getRadius(){
  return radius;
 }
 
 public double getArea(){
  return Math.PI*radius*radius;
 }
}
class Cone{
 private Circle bottom;
 private double height;
 Cone(Circle b,double h){
  bottom=b;
  
  height=h;
  
 }
 Cone(Cone cy){
  bottom=cy.bottom;
  height=cy.height;
 }
 public void setBottom(Circle b){
  bottom=b;
 }
 public void setHeight(double h){
  height=h;
 }
 public Circle getBottom(){
  return bottom;
 }
 public double getHeight(){ 
  return height;
 }
 public double getVolume(){
  double t;
  t=1/3.0*height*bottom.getArea();
  return t;
 }
}
class Example01{
 public static void main(String arg[]){
  Circle c1=new Circle(5);
  Cone cy=new Cone(c1,2);
 
 System.out.println(cy.getVolume());
 }
展开阅读全文
博主设置当前文章不允许评论。

没有更多推荐了,返回首页