2016-07-14 70 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