2016-07-14 99 views
-1

公共类Turner_A03Q1 { 公共静态类圆柱体 { 双半径; 双倍高度; (2 * Math.PI * radius * height)+(2 * Math.PI * Math.pow(radius,2)); double volume = height * Math.PI * radius * radius; 公共圆柱体(双半径,双高度) { this.radius = radius; this.height = height; } public double getRadius() { return radius; } public void setRadius(double r) { radius = r; } public double getHeight() { return height; } public void setHeight(double h) { height = h; } public double getArea() { return area; } public double getVolume() { return volume; } public String toString() return {“Cylinder Area is”+ area +“and the volume is”+ volume +“。”); } } public static void main(String [] args) {Cylinder cylinder1 = new Cylinder(5.5,7.8);圆柱类计算显示0.0

 System.out.println(cylinder1); 
    cylinder1.setRadius(2.4); 
    System.out.println(cylinder1); 
    cylinder1.setHeight(10.9); 
    System.out.println(cylinder1); 
    } 

} 

回答

0

对不起大家不知道为什么它贴出我的代码一样,

public class Turner_A03Q1 
{ 
public static class Cylinder 
    { 
double radius; 
double height; 
double area = (2 * Math.PI * radius * height) + (2 * Math.PI * Math.pow(radius, 2)); 
double volume = height * Math.PI * radius * radius; 
public Cylinder(double radius, double height) 
{ 
    this.radius = radius; 
    this.height = height; 
} 
public double getRadius() 
{ 
    return radius; 
    } 
public void setRadius(double r) 
{ 
    radius = r; 
    } 
    public double getHeight() 
    { 
     return height; 
} 
public void setHeight(double h) 
{ 
    height = h; 
} 
public double getArea() 
{ 
    return area; 
    } 
public double getVolume() 
{ 
    return volume; 
    } 
public String toString() 
{ 
    return ("Cylinder Area is " + area + " and the volume is " + volume + "."); 
} 
} 
public static void main (String [] args) 
{ 
    Cylinder cylinder1 = new Cylinder(5.5, 7.8); 

    System.out.println(cylinder1); 
    cylinder1.setRadius(2.4); 
    System.out.println(cylinder1); 
    cylinder1.setHeight(10.9); 
    System.out.println(cylinder1); 
    } 

}

+0

这是它使返回0.0 I问和人说的原因,但我只是不问题明白为什么我真的需要看看我在这里做错了什么 – zompire