已解决问题
谷歌rr772477用户在2013.10.12提交了关于“兄弟连面向对象与J**a程序设计基础”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-11-13T10:31:15。希望大家能够帮助她。详细问题描述及疑问:期待您的答案,滴水之恩,来日我当涌泉相报 !
详细问题描述及疑问:期待您的答案,滴水之恩,来日我当涌泉相报 !
1.shape接口:
publicinterfaceShape{
do
}
2.shape2D接口:
pu
doublegetCircum
}
publicinter
doublegetVolume();
}
3.Circle类:
publiccl
publicC
this.setRadius(radius);
}
@Override
publ
return2*Math.PI*ra
}
@Overri
publicdoublegetArea(){
return
}
public
this.radius=radius;
publicdoublegetRadius(){
returnradius;
}
privatedoublera
}
4.Square类:
publiccla
publicSquare(intlength,intwidth,
this.seth**eight(height);
this.setLengt
t
}
@Override
publicdoublegetVolume(){
retur
}
@Override
publicdouble
return2*length*width+2*wid
}
publicin
returnlengt
}
publicvoid
this.length=length;
}
publicintgetWidth(){
returnwidth;
}
publicvoidsetWidth(intwidth){
this.width=width;
}
publicintgeth**eight(){
returnheight;
}
publicvoidseth**eight(intheight){
this.height=height;
}
privateintlength;
privateintwidth;
privateintheight;
}
5.Scaleable接口:
publicinterfaceScableable{
voidscale(doublepropertion);
}
6.CircleScaleable类:
publicclassCircleScaleableextendsCircleimplementsScableable{
publicCircleScaleable(intradius){
super(radius);
}
@Override
publicvoidscale(doublepropertion){
super.setRadius(super.getRadius()*propertion);
}
}
7.CircleScaleable测试程序:
publicclassCircleScaleableTest{
publicstaticvoidmain(String[]args){
CircleScaleablecircle=newCircleScaleable(100);
printShape2D(circle);
circle.scale(0.5);
printShape2D(circle);
circle.scale(2.5);
printShape2D(circle);
}
publicstaticvoidprintShape2D(Shape2Dshape){
System.out.println("##############\n");
System.out.println("Circumference:"+shape.getCircumference());
System.out.println("Area:"+shape.getArea()+"\n");
}
}