class Squre extends shapeDome{ private int chang; private int kuan; public int getChang() { return chang; } public void setChang(int chang) { this.chang = chang; } public int getKuan() { return kuan; } public void setKuan(int kuan) { this.kuan = kuan; } public void girth() { setChang(10); setKuan(5); int girth =2*(getChang()+getKuan()); System.out.println("周长为"+girth); } public void area() { setChang(10); setKuan(5); int area=getChang()*getKuan(); System.out.println("面积为"+area); } }class Circle extends shapeDome{ private int banjing; public int getBanjing() { return banjing; } public void setBanjing(int banjing) { this.banjing = banjing; } public void girth() { setBanjing(5); double girth=3.14*getBanjing(); System.out.println("周长为"+girth); } public void area() { setBanjing(5); double area=3.14*getBanjing()*getBanjing(); System.out.println("面积为"+area); } }public abstract class shapeDome { public abstract void girth(); public abstract void area();}public class Initalshap { public static void main(String[] args) { Squre s=new Squre(); s.getChang(); s.getKuan(); s.girth(); s.area(); Circle c=new Circle(); c.getBanjing(); c.girth(); c.area(); }}
1 回答
一曝十寒
TA贡献13条经验 获得超2个赞
public void area() {
setChang(10);
setKuan(5);
int area=getChang()*getKuan();
System.out.println("面积为"+area);
}
}
可以改为
public void area(int A,int B) {
setChang(A);
setKuan(B);
int area=getChang()*getKuan();
System.out.println("面积为"+area);
}
}
其余类似自己改。还有一点命名长宽用英文吧,不会就下个有道词典,命名规范一点。
添加回答
举报
0/150
提交
取消