package javahomework; public class HW09 { public static void main(String args[]) { Cone r1 = new Cone(); Cone r2 = new Cone(10.0); Cone r3 = new Cone(15.0, 20.0); System.out.println("Volume is " + r1.volume() + " FaceArea is " + r1.facearea()); System.out.println("Volume is " + r2.volume() + " FaceArea is " + r2.facearea()); System.out.println("Volume is " + r3.volume() + " FaceArea is " + r3.facearea()); } } class Cone { double r, h; double pi = 3.14; Cone(double a, double b) { r = a; h = b; } Cone() { r = 1.0; h = 1.0; } Cone(double a) { r = a; h = a; } double volume() { return (pi * r * r * h) / 3; } double facearea() { return (Math.pow((r * r) + (h * h), 0.5)) * 2 * pi; } }
2008年8月29日 星期五
利用類別特性定義一個圓錐體,並且可以算出體積、表面積
code
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言