一道简单的JAVA题
编写一个圆(Circle)类,属性有半径,并提供计算面积和周长的功能。另编写一个测试类TestCircle,要求该测试类中定义一个静态常量circleNumber用来统计当前已经统计圆(Circle对象)的个数。并能计算并输出已有圆(Circle)对象的面积和周长。注意:圆周率对于所有圆都是相等的。这个怎么写啊。。。程序代码:
//Circle.java public class Circle { final double PI = 3.14; static int circleNumber = 0; private double radius; public Circle() { this.radius = 1.0; circleNumber++; } public Circle(double radius) { this.radius = radius; circleNumber++; } public double area() { return radius*radius*PI; } public double perimeter() { return 2*PI*radius; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } } //TestCircle.java public class TestCircle { public static void main(String[] args) { Circle c1 = new Circle(1.23); Circle c2 = new Circle(4.56); System.out.println(Circle.circleNumber); } }