//(1)声明一个圆柱体类型,
//(2)声明属性:底边的半径,和高
//(3)声明方法:
//A:方法的功能:在方法中打印圆柱体的详细信息:圆柱体的底边的半径是xxx,高是xxx,底面积是xxx,体积是xxx。
//B:方法的功能:返回底面积
//C:方法的功能:返回体积
//D:方法的功能:为圆柱体的底边的半径,和高赋值
//E:方法的功能:为圆柱体的底边的半径,和高赋值,并返回赋值的结果。如果底边的半径或高为<=0,赋值失败,返回false,否则返回true
//(4)并测试
public class CylinderTest
{
public static void main(String[] args)
{
Cylinder cylinder = new Cylinder();
if (cylinder.set_Height_Radius(3, 4) == true)
{
System.out.println("赋值成功");
System.out.println(cylinder.info());
} else
{
System.out.println("赋值失败");
}
}
}
class Cylinder
{
double radius;
double height;
public double getRadius()
{
return radius;
}
public void get_Height_Radius(double radius, double height)
{
this.height = height;
this.radius = radius;
}
public boolean set_Height_Radius(double radius, double height)
{
if (radius > 0 && height > 0)
{
get_Height_Radius(radius, height);
return true;
} else
{
return false;
}
}
public double getArea()
{
return Math.round(Math.PI * radius * radius);
}
public double getVolume()
{
return Math.round(getArea() * height);
}
public String info()
{
String info = "半径:" + radius + "\n高:" + height + "\n底面积:" + getArea() + "\n体积:" + getVolume();
return info;
}
}