Circle类:
import java.math.BigDecimal;
public class Circle {
private BigDecimal r;
public Circle() {
}
public Circle(BigDecimal r) {
super();
this.r = r;
}
public BigDecimal getR() {
return r;
}
public void setR(BigDecimal r) {
this.r = r;
}
public BigDecimal getArea() {
return this.getR().pow(2).multiply(new BigDecimal(Math.PI)).setScale(2, BigDecimal.ROUND_HALF_UP);
}
public BigDecimal getPerimeter() {
return this.getR().multiply(new BigDecimal(2)).multiply(new BigDecimal(Math.PI)).setScale(2,
BigDecimal.ROUND_HALF_UP);
}
}
测试类:
public class App {
public static void main(String[] args) {
BigDecimal r = new BigDecimal(3.12);
Circle c = new Circle(r);
System.out.println("圆面积为===>" + c.getArea());
System.out.println("圆周长为===>" + c.getPerimeter());
}
}
结果:
拿走不谢
小伙子好好学呀,这种很简单的,这个做不来,期末考试肯定挂了呀,怎么机试哦?