实现Java程序,包括两个类:圆柱类Cylinder和主类TestCylinder,求出圆柱体的侧面积、表面积和体积
展开全部
//Cylinder类
public class Cylinder {
private static final double PI = 3.1415926;
private double height; //圆柱体的高
private double radius; //底面半径
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public Cylinder() {}
public Cylinder(double height, double radius) {
this.height = height;
this.radius = radius;
}
public double getSideArea(){
return 2*PI*radius*height;
}
public double getFullArea(){
return (getSideArea()+PI*radius*radius*2);
}
public double getVolume(){
return PI*radius*radius*height;
}
}
//TestCylinder类
public class TestCylinder {
public static void main(String[] args) {
Cylinder cylinder = new Cylinder(5.5, 3.5);
System.out.println("圆柱体侧面积: "+cylinder.getSideArea());
System.out.println("圆柱体表面积: "+cylinder.getFullArea());
System.out.println("圆柱体体积: "+cylinder.getVolume());
}
}
public class Cylinder {
private static final double PI = 3.1415926;
private double height; //圆柱体的高
private double radius; //底面半径
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public Cylinder() {}
public Cylinder(double height, double radius) {
this.height = height;
this.radius = radius;
}
public double getSideArea(){
return 2*PI*radius*height;
}
public double getFullArea(){
return (getSideArea()+PI*radius*radius*2);
}
public double getVolume(){
return PI*radius*radius*height;
}
}
//TestCylinder类
public class TestCylinder {
public static void main(String[] args) {
Cylinder cylinder = new Cylinder(5.5, 3.5);
System.out.println("圆柱体侧面积: "+cylinder.getSideArea());
System.out.println("圆柱体表面积: "+cylinder.getFullArea());
System.out.println("圆柱体体积: "+cylinder.getVolume());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询