zoukankan      html  css  js  c++  java
  • 计算圆

    代码有点多

    代码如下:

    package Day07;

    public class Circle4 extends GeometricObject1 {
    private double radius;

    /**
    *
    */
    public Circle4() {
    }

    /**
    * @param radius
    */
    public Circle4(double radius) {
    this.radius = radius;
    }

    public Circle4(double radius, String color, boolean isFilled) {
    this.radius = radius;
    setColor(color);
    setFilled(isFilled);
    }

    public double getRadius() {
    return this.radius;
    }

    public void setRadius(double radius) {
    this.radius = radius;
    }

    public double getArea() {
    return this.radius * this.radius * Math.PI;
    }

    public double getPerimeter() {
    return this.radius * 2 * Math.PI;
    }

    public double getDiameter() {
    return this.radius * 2;
    }

    public void printCircle(){
    System.out.println("the radius is " + this.radius + " Created on " + getDateCreated());
    }
    }

    二部分

    package Day07;
    import java.util.Date;
    public class GeometricObject1 {
    private String color;
    private boolean isFilled;
    private Date dateCreated;
    /**
    *
    */
    public GeometricObject1() {
    this.dateCreated = new Date();
    }
    /**
    * @param color
    * @param isFilled
    */
    public GeometricObject1(String color, boolean isFilled) {
    this.color = color;
    this.isFilled = isFilled;
    this.dateCreated = new Date();
    }
    /**
    * @return the color
    */
    public String getColor() {
    return this.color;
    }
    /**
    * @param color the color to set
    */
    public void setColor(String color) {
    this.color = color;
    }
    /**
    * @return the isFilled
    */
    public boolean isFilled() {
    return this.isFilled;
    }
    /**
    * @param isFilled the isFilled to set
    */
    public void setFilled(boolean isFilled) {
    this.isFilled = isFilled;
    }
    /**
    * @return the dateCreated
    */
    public Date getDateCreated() {
    return this.dateCreated;
    }

    /* (non-Javadoc)
    * @see java.lang.Object#toString()
    */
    @Override
    public String toString() {
    return "GeometricObject1 [color=" + color + ", isFilled=" + isFilled
    + ", dateCreated=" + dateCreated + "]";
    }

    }

    输出

    package Day07;

    public class TestGeometric {
    public static void main(String[] args) {
    Circle4 c1 = new Circle4(10.0);
    System.out.println(c1.getArea());
    System.out.println(c1.getDiameter());
    System.out.println(c1.getPerimeter());
    System.out.println(c1.isFilled());
    c1.printCircle();
    }
    }

    只相信苦尽甘来
  • 相关阅读:
    Shell编程-05-Shell中条件测试与比较
    Shell编程-04-Shell中变量数值计算
    Shell编程-03-Shell中的特殊变量和扩展变量
    Shell编程-02-Shell变量
    Shell编程-01-Shell脚本初步入门
    Windows与Linux相互远程桌面连接
    awk基础05-自定义函数和脚本
    使用Kafka Connect创建测试数据生成器
    设置KAFKA
    Apache Kafka使用默认配置执行一些负载测试来完成性能测试和基准测试
  • 原文地址:https://www.cnblogs.com/F001li/p/7055883.html
Copyright © 2011-2022 走看看