面向对象与J**a程序设计基础

时间:2013.10.12 发布人:rr772477

面向对象与J**a程序设计基础

已解决问题

谷歌rr772477用户在2013.10.12提交了关于“兄弟连面向对象与J**a程序设计基础”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-11-13T10:31:15。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,滴水之恩,来日我当涌泉相报 !

希望以下的回答,能够帮助你。

第1个回答

用户名:px7988  

1.shape接口:
publicinterfaceShape{

do来自ublegetArea();

}
2.shape2D接口:
publicinterfaceShape2DextendsShape{

doublegetCircum权编研坚北留笑济ference();
}
问答shape3D接口:
publicinterfaceShape3DextendsShape{

doublegetVolume();
}
3.Circle类:
publiccl办兴而推assCircleimplementsShape2D{

publicCircle(doubleradius){
this.setRadius(radius);
}

@Override
publicdoublegetCircumference(){
return2*Math.PI*radius;
}

@Overri切必假征沉策空误提左运de
publicdoublegetArea(){
return步款配正卷起明式处迫Math.PI*radius*坏孩乐radius;
}

public对来哥呀而视反voidsetRadius(doubleradius){
this.radius=radius;
}

publicdoublegetRadius(){
returnradius;
}

privatedoubleradius;

}
4.Square类:
publiccla活及洲判缺ssSquareimplementsShape3D{

publicSquare(intlength,intwidth,intheight){
this.seth**eight(height);
this.setLengt觉供优济沿品率景声续h(length);
t照建备树定鲜永距his.setWidth(wi王洲够员dth);
}

@Override
publicdoublegetVolume(){
retur害染略采击跳良nlength*width*height;
}

@Override
publicdouble黑息规许鲜约望费合逐getArea(){
return2*length*width+2*wid占白位两第乙胡大领th*height+2*length*height;
}

publicin而子tgetLengt系h(){
returnlengt念波h;
}

publicvoid只久酸齐setLength(intlength){
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");
}

}