浙江省预约挂号系统:用java程序计算 圆面积
public class Test {
public static void main(String[] args) {
double radius = 3;
final double PI= 3.15169;
double area = radius * radius * PI;
System.out.println("Area is " + area);
}
}
//测试通过,PI怎么时3.15169的?
interface Shape
{
final double PI = 3.15169;
double getArea();
}
class Circle implements Shape
{
private double radius;
public Circle(double r) {this.radius = r;}
public double getRadius() {return this.radius;}
public void setRadius(double r) {this.radius = r;}
public double getArea()
{
return radius * radius * PI;
}
}
public class Test
{
public static void main(String[] args)
{
Circle c = new Circle(3);
System.out.println("Area is " + c.getArea());
}
}
class Round
{
double radius ;
final double PI= 3.15169;
Round(double radius)
{
this.radius=radius;
}
public double getArea()
{
return radius * radius * PI;
}
}
public class TestRound
{
public static void main(String[] args)
{
Round round=new Round(3);
System.out.println("Area is " + round.getArea());
}
}