计算圆

Posted 辰峰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了计算圆相关的知识,希望对你有一定的参考价值。

代码有点多

代码如下:

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();
}
}

以上是关于计算圆的主要内容,如果未能解决你的问题,请参考以下文章

求用python输入圆的半径,计算圆的周长和面积,结果保留2位小数的代码

用python计算圆的面积?

计算圆的面积的程序

计算几何如何计算两个圆的交点坐标

创建一个圆类Circle的对象,分别设置圆的半径计算并分别显示圆半径圆面积圆周长。

Day023 计算圆面积