zoukankan      html  css  js  c++  java
  • 第八章

    源代码:


    interface Volume{public double volume();}
    interface Area{public double area();}

    class yuanzhui extends Object implements Area,Volume
    {
    private double radius;
    private double length;
    private double height;
    public yuanzhui(double radius,double length,double height)
    {
    this.radius = radius;
    this.length = length;
    this.height = height;
    }
    public yuanzhui()
    {
    this(0,0,0);
    }
    public double area()
    {
    return Math.PI*this.radius*this.length+Math.PI*this.radius* this.radius ;
    }
    public double volume()
    {
    return Math.PI * this.radius * this.radius * this.height/3;
    }
    public String toString()
    {
    return "一个圆锥,半径"+this.radius+",高"+this.height+",斜边,"+this.length+"表面积为"+this.area()+",体积为"+this.volume();
    }
    public static void main(String args[])
    {yuanzhui a=new yuanzhui(6,5,4);
    System.out.println(a);
    yuanzhui b=new yuanzhui(9,8,7);
    System.out.println(b);
    if(a.volume()>b.volume())
    System.out.println("第一个圆锥的体积大于第二个圆锥的体积");
    else
    System.out.println("第一个圆锥的体积小于第二个圆锥的体积");

    }
    }

     

    结果:

    一个圆锥,半径6.0,高4.0,斜边,5.0表面积为207.34511513692632,体积为150.79644737231007
    一个圆锥,半径9.0,高7.0,斜边,8.0表面积为480.6636759992383,体积为593.7610115284709
    第一个圆锥的体积小于第二个圆锥的体积

    心得:

    1.经过编写和调试认识和了解了接口的使用和接口的作用。

    2.在编写的时候还是存在一些未知的错误,还需要加强编写能力。

  • 相关阅读:
    HTML5就是现在:深入了解Polyfills
    dot.js-js模板引擎使用,教程,入门
    js操作dom对象
    JavaScript中this详解
    浅谈JavaScript中的string拥有方法的原因
    函数定义方式
    Jquery的跨域调用
    数据结构与算法之美-排序(下)
    CLR via C#学习笔记-第十三章-定义接口、继承接口
    CLR via C#学习笔记-第十二章-可验证性和约束
  • 原文地址:https://www.cnblogs.com/Z-js/p/10860569.html
Copyright © 2011-2022 走看看