⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5例子10.txt

📁 java电子版源码 java电子版源码
💻 TXT
字号:
abstract class Geometry 
{  
    public abstract double ComputerArea();
}
class Lader extends Geometry 
{ 
    double a,b,h;
    Lader(double a,double b,double h)
    {  
       this.a=a;this.b=b;this.h=h;
    }
    public double ComputerArea() 
    {  
         return((1/2.0)*(a+b)*h);
    }
}
class Circle extends Geometry  
{  
    double r;
    Circle(double r)
    {  
       this.r=r;
    }
    public double ComputerArea()
    {  
       return(3.14*r*r);
    }
}
class Cone 
{  
    Geometry bottom;
    double height;
    Cone(Geometry bottom,double height) 
    { 
        this.bottom=bottom;
        this.height=height;
    }
    void changBottom(Geometry bottom) 
    {
        this.bottom=bottom;
    }
    public double ComputerVolume() 
    {  
       return (bottom.ComputerArea()*height)/3.0;
    }
}
public class Example
{ 
    public static void main(String args[]) 
    { 
       Cone cone;
       Geometry geometry;
       geometry=new Lader(2.0,7.0,10.7);
       System.out.println("梯形的面积"+geometry.ComputerArea());
       cone=new Cone(geometry,30);
       System.out.println("梯形底的锥的体积"+cone.ComputerVolume());
       geometry=new Circle(10);
       System.out.println("半径是10的圆的面积"+geometry.ComputerArea());
       cone.changBottom(geometry);
       System.out.println("圆形底的锥的体积"+cone.ComputerVolume());
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -