2013-04-05 46 views
0

我写了一个类,现在我试图测试它,并且我的类测试中出现错误,说“Cylinder中的CylinderTest.java:9:getHeight()不能应用于(double)”Java classTest error

这里是我的类代码:

public class Cylinder 
private double Radius; 
private double Height; 
public final static double Pi = 3.14159; 
// constructor 
public Cylinder() 
{ 
    Radius = 0.0;{ 

    Height = 0.0; 
} 
// getRaduis method 
public double getRadius() 
{  
    return Radius; 
} 
// getHeight method 
public double getHeight() 
{ 

    return Height; 
} 
// setRadius method 
public void setRadius(double r) 
{ 
    Radius = r; 
} 
// setHeight method 
public void setHeight(double h) 
{ 
    Height = h; 
} 
// getSurfaceArea 
public double getBaseArea(double BaseArea) 
{ 
    BaseArea = Radius * Radius * Pi; 
    return BaseArea; 
} 
// getVolume 
public double getVolume(double BaseArea, double Volume) 
{ 
    Volume = BaseArea * Height; 
    return Volume; 
} 
// Print 
//System.out.println("The volume of the cylinder is " +Volume); 

}

,这里是为classTest代码:

public class CylinderTest { 
    public static void main(String[] args) 
    { 
     Cylinder cylinderA = new Cylinder(); 
     cylinderA.getRadius(3.5); 
     cylinderA.getHeight(4.5); 
     System.out.println(cylinderA.getVolume()); 
    } 
} 

我写的原始圆柱体类编译得很好我在尝试编译classTest时遇到了麻烦。任何帮助将不胜感激。

+0

getRadius和getHeight函数没有双精度参数,所以不能像这样调用它们。我认为你需要使用setRadius和setHeight – Ken 2013-04-05 20:45:00

回答

0

你调用你的getter方法时,它看起来像你应该打电话给你的setter方法:

cylinderA.setHeight(4.5); 
//  ^

如果你真的打算打电话给你的getter方法,然后调用它像这样:

double height = cylinderA.getHeight(); 

因为getHeight没有任何参数。

+0

如何在classCylinder中创建setVolume方法来打印音量? – Smed910 2013-04-05 21:38:34

+0

如何在classCylinder中创建setVolume方法来打印卷? – Smed910 2013-04-05 23:14:01