?class Cuboid { double a; double b;? ? ? ? ? ? ?double h;? ? ? ? ? ? ?double area; public Cuboid(double a, double b,double h){ this.a = a; this.b = b; this.h = h; } public Cuboid() { // TODO Auto-generated constructor stub } double Area(){ area=a*b*h; return area; } }? ?public class ?Test67{?? ?public static void main(String args[]){ ? Cuboid cuboid = new Cuboid(); ? double a=12.5,b=5.2,h=2.5; ? Cuboid.Cuboid(a,b,h); ? System.out.println("長方提體的體積是:"+cuboid.Area());}}這是題目:1.?編程擴展下面的矩形類(Rect)為長方體類(Cuboid),要求增加高度(h)屬性,并求出長方體的體積(Volume)。public?class?Rect?{double?a;double?b;?public?Rect(double?a,?double?b){this.a?=?a;this.b?=?b;}public?double?Area(){return?a?*?b;}}
1 回答
已采納

Its_forever
TA貢獻361條經(jīng)驗 獲得超328個贊
public?class?Rect?{ double?a; double?b; double?c; //帶三個參數(shù)(長寬高)的構(gòu)造函數(shù) public?Rect(double?a,?double?b,double?c){ this.a?=?a; this.b?=?b; this.c?=?c; } public?double?Area(){ return?a?*?b*?c; } public?static?void?main(String[]?args)?{ Rect?r?=?new?Rect(2.1,3.2,4.3); System.out.println(r.Area()); } }
添加回答
舉報
0/150
提交
取消