java编写
计算球体体积,圆柱体体积,立方体体积
用方法重载编程,我不用重载的会,这重载的就不会了
还是就是形参要用几个
[code="java"]
public interface Graph
{
public double volume();
}
//圆柱
public class Cylinder implements Graph
{
private double radius;
public Cylinder(double radius) {
this.radius = radius;
}
@Override
public double volume()
{
//计算体积公式
return 0;
}
}
//长方
public class Cuboid implements Graph
{
private double width;
private double height;
private double length;
public Cuboid(double width, double height, double length)
{
this.width = width;
this.height = height;
this.length = length;
}
@Override
public double volume()
{
// 公式
return 0;
}
}
//工具
public class ComputeUtil
{
public static double computeVolume(Graph graph) {
return graph.volume();
}
}
[/code]