其他分享
首页 > 其他分享> > 实验八

实验八

作者:互联网

package 项目;
interface Area
{
public abstract double area();
}
interface Volume
{
public abstract double volume();
}
public class yuanzhui extends Object implements Area,Volume
{
int height,raduis,length;
public yuanzhui(int height,int raduis,int length)
{
this.height=height;
this.raduis=raduis;
this.length=length;
}
public double area()
{
return (Math.PI*raduis*length+Math.PI*raduis*2);
}
public double volume()
{
return height*Math.PI*raduis*2/3;
}
public static double max(yuanzhui X,yuanzhui Y)
{
System.out.print("体积较大圆锥体体积为:");
if(X.volume()>Y.volume())
return X.volume();
else
return Y.volume();
}

public static void main(String[] args) {
yuanzhui YZ=new yuanzhui(3,4,5);
yuanzhui yz=new yuanzhui(4,5,6);
System.out.println("圆锥1表面积为:"+YZ.area());
System.out.println("圆锥2表面积为:"+yz.area());
System.out.println("圆锥1体积为:"+YZ.volume());
System.out.println("圆锥2体积为:"+yz.volume());
System.out.println("圆锥体积较大的为:"+Math.max(yz.volume(),YZ.volume()));
}
}

 

圆锥1表面积为:87.96459430051421
圆锥2表面积为:125.66370614359172
圆锥1体积为:25.132741228718345
圆锥2体积为:41.88790204786391
圆锥体积较大的为:41.88790204786391

标签:yuanzhui,System,volume,raduis,圆锥,实验,public
来源: https://www.cnblogs.com/1314521-ww/p/10878502.html