• 【每日日报】第八天


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

  • 相关阅读:
    4.JDBC编程
    android 多线程
    android 网络请求Ⅰ
    android 数据存储Ⅱ
    android 数据存储Ⅰ
    android 界面设计基本知识Ⅳ
    《将博客搬至CSDN》
    android 界面设计基本知识Ⅲ
    android 界面设计基本知识Ⅱ
    android 界面设计基本知识
  • 原文地址:https://www.cnblogs.com/linmob/p/13297596.html
Copyright © 2020-2023  润新知