【每日日报】第十四天

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 明天继续做题

原文地址:https://www.cnblogs.com/linmob/p/13345731.html