我寫了一個類,現在我試圖測試它,並且我的類測試中出現錯誤,說「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時遇到了麻煩。任何幫助將不勝感激。
getRadius和getHeight函數沒有雙精度參數,所以不能像這樣調用它們。我認爲你需要使用setRadius和setHeight – Ken 2013-04-05 20:45:00