1. 程式人生 > >計算圓

計算圓

javadoc ack void clas sys stat imp dia rri

代碼有點多

代碼如下:

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

計算圓