首页 > 其他 > 详细

实验八

时间:2019-05-19 13:15:50      阅读:96      评论:0      收藏:0      [点我收藏+]

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

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

 

实验结果

技术分享图片

 

实验心得:

1.学会了对接口的定义和声明,关键字interface不可缺少;

2.实验中还是有很多问题不是很清楚,加强练习。

实验八

原文:https://www.cnblogs.com/1998bmx/p/10888842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!