zoukankan      html  css  js  c++  java
  • p134 java


    abstract class Geometry
    {
    public abstract double getArea();
    }

    class Pillar
    {
    Geometry bottom;
    double height;
    Pillar(Geometry bottom,double height)
    {
    this.bottom = bottom;
    this.height=height;
    }
    public double getVolume()
    {
    if(bottom==null)
    {
    System.out.println("没有底,无法计算体积!");
    return -1;
    }
    return bottom.getArea()*height; //求真正的体积;
    }
    }

    class Circle extends Geometry
    {
    double r;
    Circle(double rr)
    {
    this.r=rr;
    }
    public double getArea()
    {
    return 3.14*r*r;
    }
    }

    class Rectangle extends Geometry
    {
    double a,b;
    Rectangle(double aa,double bb)
    {
    this.a=aa;
    this.b=bb;
    }
    public double getArea()
    {
    return a*b;
    }

    }

    public class Appli {
    public static void main(String []args)
    {
    Pillar pillar;
    Geometry bottom=null;
    pillar=new Pillar(bottom,100);
    System.out.println("体积"+pillar.getVolume());
    bottom=new Rectangle(12,22);
    pillar=new Pillar(bottom,58);
    System.out.println("体积"+pillar.getVolume());
    bottom=new Circle(10);
    pillar=new Pillar(bottom,58);
    System.out.println("体积"+pillar.getVolume());
    }

    }

  • 相关阅读:
    [JSOI2009] 游戏
    CF1148H Holy Diver
    [提高组集训2021] 模拟赛3
    CF1458F Range Diameter Sum
    [游记] CSP2021
    CF1396E Distance Matching
    CF1396D Rainbow Rectangles
    【LeetCode】1. 两数之和
    【随笔】开通博客园过程
    MyISAM与InnoDB的区别是什么?
  • 原文地址:https://www.cnblogs.com/duanqibo/p/14032676.html
Copyright © 2011-2022 走看看