作业帮 > 综合 > 作业

JAVA声明圆柱体类和圆锥体类,继承矩形类rectangle并实现volume借口,计算表面积和体积

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/12 09:26:47
JAVA声明圆柱体类和圆锥体类,继承矩形类rectangle并实现volume借口,计算表面积和体积
要代码哦~注意继承的不是圆~
和圆锥体类
public class Du {
\x05public static void main(String[] args) {
\x05}
}
class Rectangle{
\x05protected double length;
\x05protected double width;
\x05
\x05public Rectangle(double length,double width){
\x05\x05this.length = length;
\x05\x05this.width = width;
\x05}
}
interface Volume{
\x05public double volume();
}
class YuanZhu extends Rectangle implements Volume{//圆柱体类
\x05private double r;
\x05
\x05public YuanZhu(double length,double width) {
\x05\x05super(length,width);
\x05\x05this.r = length / 2 / Math.PI;
\x05}
\x05public double volume() {
\x05\x05return Math.PI * Math.pow(r,2) * width;
\x05}
}
class YuanZhui extends Rectangle implements Volume{//圆锥体类
\x05private double r;
\x05
\x05public YuanZhui(double length,double width) {
\x05\x05super(length,width);
\x05\x05this.r = length /2 / Math.PI;
\x05}
\x05public double volume() {
\x05\x05return Math.PI * Math.pow(r,2) * width / 3;
\x05}
\x05
}