求一java程序 求圆和矩形面积 在线等 面向对象的~~

2024-11-20 09:40:58
推荐回答(1个)
回答1:

Area 类:

public abstract interface Area {

public double area(double a, double b);
}
RectArea 类:
public interface RectArea extends Area{
public double area(double a, double b);
}
RoundArea 类:
public interface RoundArea extends Area{

public double area(double a,double b);

}
ImpleArea :实现类
public class ImpleArea implements Area,RectArea,RoundArea{

public double area(double a, double b) {
double temp =0d;
//圆的面积 a半径 b半径
if(a==b){
temp=3.14*a*b;
}
//长方形的面积
else{
temp=a*b;
}
return temp;
}

}

希望我的答案你能满意~~~