zoukankan      html  css  js  c++  java
  • 【每日日报】第十四天

    1 今天写了Cylinder类

    题目要求:

     

     

     

     

     

     

     

     程序源代码:

    package Plane;
    public class Cylinder extends Circle{
      double height;
      Cylinder(){super(0,0,0);height=0;}
      Cylinder(double xx,double yy,double rr,double hh)
          {
          super(xx,yy,rr);
              height=hh;
              System.out.println("Cylinder Constructor run");
          }
          Cylinder(Cylinder v)
          {
           super(v);
              height=v.height;
              System.out.println("Cylinder CopyConstructor run");
          }
          void setH(double hh){height=hh;}
          double getH(){return height;}
          void show()                    //用于显示球的信息
          {
           System.out.print("Cylinder(");
              super.show();
              System.out.println(",Height="+height+")");
          }
          double s_Area()          //用于计算球的面积
          {
              double s;
              double r=getR();
              s=2*PI*r*r+2*PI*r*height;
              return s;
          }
          double volume()          //用于计算球的体积
          {
              double v;
              double r=getR();
              v=PI*r*r*height;
              return v;
          }
    }
     
    package Plane;
    import java.util.Scanner;
    public class CylinderMa extends Cylinder{
     void show(Point p){/*点基类的显示函数*/
         p.show();
     }
     void length(Plane p){/*平面图形的周长函数*/
      System.out.println("Length="+p.length());
     }
     void area(Plane p){/*平面图形的面积函数*/
      System.out.println("Area="+p.area());
     }
     void volumn(Cylinder s){/*立体图形的体积函数*/
      System.out.println("Volumn="+s.volume());
     }
     void s_Area(Cylinder s){/*立体图形的表面积函数*/
      System.out.println("S_Area="+s.s_Area());
     }
     public static void main(String[] args)
     {
      double  h;
      Scanner in=new Scanner(System.in);
      h=in.nextDouble();
      Cylinder cy1=new Cylinder(1,2,3,4);
      Cylinder cy2=new Cylinder(cy1);
      CylinderMa m=new CylinderMa();
      m.show(cy1);
      System.out.println();
      m.area(cy1);
      m.length(cy1);
      m.s_Area(cy1);
      m.volumn(cy1);
      cy2.setH(h);
            m.show(cy2);
            System.out.println();
            m.area(cy2);
            m.length(cy2);
         m.s_Area(cy2);
         m.volumn(cy2);
         in.close();
     }
    }

     运行截图:

     

     

    2 打代码的速度比以前快了很多,有一些问题不用百度自己也知道怎么回事了

    3 明天继续做题

  • 相关阅读:
    android学习十四(android的接收短信)
    C/C++知识要点4——printf函数以及cout的计算顺序
    HDU 5355 Cake(2015多校第六场,搜索 + 剪枝)
    微信错误提示code= -4/微信发送被拒绝
    struts2的validate在使用过程中的一个问题
    28.字符串的排列
    Redis入门经典——The Little Redis Book (翻译)
    POJ 3155 Hard Life(最大密度子图)
    BZOJ 1798 AHOI2009 Seq 维护序列 线段树
    RT-Thread开篇
  • 原文地址:https://www.cnblogs.com/linmob/p/13345731.html
Copyright © 2011-2022 走看看