急!求程序!JAVA设计圆柱体的类,计算其表面积和体积
public class Cylinder {//圆柱体类
在金水等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、网站设计 网站设计制作按需求定制制作,公司网站建设,企业网站建设,品牌网站建设,全网整合营销推广,外贸网站建设,金水网站建设费用合理。
private double radius;
private double height;
public Cylinder(){}//无参构造
public Cylinder(double 御册radius,double height){
this.radius = radius;
this.height = height;
}
public double getPerimeter(){//得到底圆周塌拆陆长
return 2 * Math.PI * this.radius;
}
public double getBottomArea(){//得到底面积
return Math.PI * this.radius * this.radius ;
}
public double getVolume(){//得到体积
return this.getBottomArea() * this.height;
}
public double getArea(){//得到表面积
return this.getBottomArea()*2 + this.getPerimeter() * this.height;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
}
public class RingCylinder extends Cylinder {
private double outerRadius;//外半径
private double interRadius;//内半径
private double height;
public RingCylinder(){}
public RingCylinder(double outerRadius,double interRadius,double height){
this.outerRadius = outerRadius;
this.interRadius = interRadius;
this.height = height;
}
@Override
public double getPerimeter() {//得到内圆周长和外圆周长的和
return 2 * Math.PI * (this.outerRadius + this.interRadius);
}
@Override
public double getBottomArea() {//得到底部面积
return Math.PI * (this.outerRadius - this.interRadius) * (this.outerRadius - 团顷this.interRadius);
}
@Override
public double getVolume() {//得到体积
return this.getBottomArea() * this.height;
}
@Override
public double getArea() {
return this.getBottomArea()*2 + this.getPerimeter()*this.height;
}
public double getOuterRadius() {
return outerRadius;
}
public void setOuterRadius(double outerRadius) {
this.outerRadius = outerRadius;
}
public double getInterRadius() {
return interRadius;
}
public void setInterRadius(double interRadius) {
this.interRadius = interRadius;
}
public double getHeight() {
return this.height;
}
public void setHeight(double height) {
this.height = height;
}
}
JAVA基础实现圆类Circle
/////写着也够累的....
public class Cylinder extends Circle{
private double h;
public Cylinder(double h, double r, int x, int y) {
super(r, x, y);
this.h = h;
}
public Cylinder(){
}
public double getH() {
return h;
}
public void setH(double h) {
this.h = h;
}
public double area(){
return 2 * super.area() + super.perimeter() * h;
}
public double volume() {
return super.area() * h;
}
public static void main(String[] args) {
Cylinder cy = new Cylinder(4.5, 2.3, 2 , 3);
System.out.println("area: " + cy.area());
System.out.println("volume: " + cy.volume());
}
}
class Circle{
private int x;
private int y;
private double r;
public Circle(){
}
public Circle(double r, int x, int y) {
this.r = r;
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public double getR() {
return r;
}
public void setR(double r) {
this.r = r;
}
public double perimeter(){
return 2 * Math.PI * r;
}
public double area(){
return Math.PI * r * r;
}
}
当前题目:Java圆柱代码 java实现圆柱表面积和体积
分享网址:http://lswzjz.com/article/dsppscs.html