如何用java编写类Circle和类Rectangle
1个回答
展开全部
class Circle implements Ishape{
final pi = 3.1415926;
private double radius;
;
public Circle(double r){
radius = r;
}
public double perimeter(){
return 2*pi*radius;
}
public double area(){
return pi*radius*radius;
}
}
class Rectang implements Ishape{
private double width;
private double height;
public rectang(double w,double h){
width = w;
height = h;
}
public double perimeter(){
return (width + height)*2;
}
public double area(){
return width*height;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询