package 计算圆锥体面积;
class abc extends yuanzhuiti implements Area,Volume {
final double PI=3.14;
public double volume(double r,double h) {
double v;
v=r*h/3;
return v;
}
public double area(double r,double l) {
double a;
a=PI*r*l+PI*r*r;
return a;
}
}
public class yuanzhuiti{
public static void main(String[] args) {
abc a=new abc();
abc b=new abc();
System.out.println("圆锥体A的面积为:"+a.area(2, 4));
System.out.println("圆锥体A的体积为:"+a.volume(3, 6));
System.out.println("圆锥体B的面积为:"+b.area(3, 6));
System.out.println("圆锥体B的体积为:"+b.volume(4, 8));
System.out.println("体积较大的是:"+Math.max(a.area(3, 6), b.volume(4, 8)));
}
}
package 计算圆锥体面积;
public interface Area{
public abstract double area(double r,double l);
}
package 计算圆锥体面积;
public interface Volume {
public abstract double volume(double r,double h);
}
实验结果:
圆锥体A的面积为:37.68
圆锥体A的体积为:6.0
圆锥体B的面积为:84.78
圆锥体B的体积为:10.666666666666666
体积较大的是:84.78
实验心得:只要明白接口的性质,就可以完成实验