1.?編程求矩形面積和圓面積,要求:(1)?分別編寫(xiě)矩形類(lèi)(屬性為寬和高)、圓類(lèi)(屬性為半徑)實(shí)現(xiàn)下面的接口:interface?CalcArea?{?????public?double?Area();}(2)?主類(lèi)的主方法中分別輸出一個(gè)矩形和一個(gè)圓的面積。?下面是我寫(xiě)是的代碼,但是好像不行,求大神指點(diǎn)哦。interface CalcArea{ public double Area();}class Rect implements CalcArea{? ? public double ?weight ,height; double ?s; s = weight*height;}System.out.print("矩形的面積為:"+s);public class Test11 {}?class cicle implements CalcArea{?public double ?r; ??public ?double S; S = 3.14*r*r;}System.out.println("園形的面積為:"+S);public class Test11 { public static void main(String args[]){ Rect rect = new Rect(); rect.Area(); Cicle cicle = new Cicle(); cicle.Area(); }}
1 回答
已采納

一條小咸魚(yú)
TA貢獻(xiàn)457條經(jīng)驗(yàn) 獲得超255個(gè)贊
建議你還是多看看JAVA類(lèi)基礎(chǔ)吧
public?class?Rect?implements?CalcArea?{ ????private?double?width; ????private?double?height; ????@Override ????public?double?Area()?{ ????????//?TODO?自動(dòng)生成的方法存根 ????????return?width?*?height; ????} }
--------------------------------------------
public?class?Test?{ ????public?static?void?main(String[]?args)?{ ????????//?TODO?自動(dòng)生成的方法存根 ????????Rect?rect?=?new?Rect(); ????????double?area?=?rect.Area(); ????????System.out.println(area); ????} }