java,
分享于 点击 28592 次 点评:208
java,
11.求圆的,长方形的面积周长
public class Cricle implements Shape2D{
double radius ;//定义圆的半径
public Cricle(double r){
radius=r;
}
public double grith(){
return PI*radius*2;
}
public double area(){
return PI*radius*radius;
}
}
public class Rectangle implements Shape2D {
double width,height;
public Rectangle(double w,double h){
width=w;
height=h;
}
public double grith() {
// TODO Auto-generated method stub
return 2*(width+height);
}
public double area() {
// TODO Auto-generated method stub
return width*height;
}
}
}
public interface Shape2D {
final double PI=3.14;
double grith();
double area();
}
相关文章
- 暂无相关文章
用户点评