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

    1 今天写了

     题目要求:

     

     

     程序源代码:

    package Point;
    public class Point {
       double x;
         double y;
         Point()//有参构造
         {
          x=0;
          y=0;
             System.out.println("Point Constructor run");
         }
         Point(double xv,double yv)//有参构造
         {
          x=xv;
          y=yv;
             System.out.println("Point Constructor run");
         }
         Point(Point p)            //拷贝构造
         {
          x=p.x;
          y=p.y;
             System.out.println("Point CopyConstructor run");
         }
         void show()            //显示Point信息
         {
          System.out.println("("+x+","+y+")");
         }
         double area(){return 0;}           //面积=0
         void setX(double xv){x=xv;}        //设置X坐标
         void setY(double yv){y=yv;}        //设置Y坐标
         double getX() {return x;}           //获取X坐标
         double getY() {return y;}           //获取Y坐标
    }
    package Point;
    import java.util.Scanner;
    public class Circle extends Point{
     public static void main(String[] args){
      Scanner input = new Scanner(System.in);
         double r = input.nextDouble();
         Circle c1=new Circle(1,2,4);
         Circle c2=new Circle();
         Circle c3=new Circle(c1);
         c1.show();
         System.out.println();
         System.out.println("Area="+c1.area());
         System.out.println("Circumference="+c1.circumference());
         c2.show();
         System.out.println();
         System.out.println("Area="+c2.area());
         System.out.println("Circumference="+c2.circumference());
         c3.setRadius(r);
         c3.show();
         System.out.println();
         System.out.println("Area="+c3.area());
         System.out.println("Circumference="+c3.circumference());
         input.close();
     }
     static double PI=3.14159;
     double radius;
     Circle()
        {
         x=0;
         y=0;
            radius=0;
            System.out.println("Circle Constructor run");
        }
     Circle(double xx)
        {
         x=xx;
         y=0;
            radius=0;
            System.out.println("Circle Constructor run");
        }
        Circle(double xx,double yy,double rr)
         {
             x=xx;
             y=yy;
             radius=rr;
             System.out.println("Circle Constructor run");
         }
      Circle(Circle cir)
         {
          x=cir.x;
          y=cir.y;
             radius=cir.radius;
             System.out.println("Circle CopyConstructor run");
         }
      void setRadius(double r){radius=r;}
      double getRadius() {return radius;}
         double circumference() {return 2*PI*radius;}        //用于计算圆的周长
         double area() {return PI*radius*radius;}            //用于计算圆的面积
         void show() {System.out.println("("+x+","+y+"),"+"Radius="+getRadius());}
    }

     运行截图:

    2 类的继承用extend  public class Circle extends Point

    3 明天继续做题

  • 相关阅读:
    『参考』.net CF组件编程(3)——在移动设备项目中使用组件
    『原创』+『参考』PPC丢失后,手机信息如何保护?(C#)
    索引贴——移动开发(.Net CF 停止更新)
    NavReady 试用小记(1)
    第一次做webcast
    Webcast预告
    恼人的"don't know how to make"错误
    在这里开博了
    针对导航产品,微软推出NavReady 2009
    NavReady的使用
  • 原文地址:https://www.cnblogs.com/linmob/p/13297596.html
Copyright © 2011-2022 走看看