预览加载中,请您耐心等待几秒...
1/4
2/4
3/4
4/4

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

//实验四第一题源程序 classPoint2D { intx; inty; Point2D(intx,inty) { this.x=x; this.y=y; } voidoffset(inta,intb) { x=x+a; y=y+b; System.out.println("平移后:"+x+","+y); } voidprint(Point2Dp2d1,Point2Dp2d2) { doubleL1=Math.sqrt(Math.pow((p2d1.x-p2d2.x),2)+Math.pow((p2d1.y-p2d2.y),2)); System.out.println("L1="+L1); } } classPoint3DextendsPoint2D { intz; Point3D(intx,inty,intz) { super(x,y); this.z=z; } Point3D(Point2Dp,intz) { super(p.x,p.y); this.z=z; } voidoffset(inta,intb,intc) { x=x+a; y=y+b; z=z+c; } voidprint(Point3Dp3d1,Point3Dp3d2) { doubleL2=Math.sqrt(Math.pow((p3d1.x-p3d2.x),2)+Math.pow((p3d1.y-p3d2.y),2)+Math.pow((p3d1.z-p3d2.z),2)); System.out.println("L2="+L2); } publicstaticvoidmain(String[]args) { Point2Dp2d1=newPoint2D(2,3); Point2Dp2d2=newPoint2D(4,5); Point3Dp3d1=newPoint3D(2,3,4); Point3Dp3d2=newPoint3D(4,5,6); p2d1.print(p2d1,p2d2); p3d1.print(p3d1,p3d2); } } //实验四第二题源程序 abstractclassShape { abstractpublicvoidshowArea(); } interfaceDiagArea { doublegetDiagonal(); doublegetArea(); } classRectangleimplementsDiagArea { intw,h; Rectangle(inti,intj) { w=i; h=j; } publicvoidshowArea() { ints1=w*h; System.out.println("s矩形="+s1); } publicdoublegetDiagonal() { doubleL=Math.sqrt(w*w+h*h); System.out.println("对角线长="+L); returnL; } publicdoublegetArea() { doubles=w*h; System.out.println("S矩形面积="+s); returns; } } classSquareextendsRectangle {intx; Square(intx) { super(x,x);//此处修改前为x=i; this.x=x; } publicvoidshowArea() { ints2=x*x; System.out.println("s正方形="+s2); } } classCircle { intr; Circle(inti) { r=i; } publicvoidshowArea() { doubles3=Math.PI*(r*r); System.out.println("s圆="+s3); } voidshow() { System.out.println("圆的半径="+r); } } classAreas { publicstaticvoidmain(String[]args) { RectangleRe=newRectangle(2,3); SquareSq=newSquare(4); CircleCi=newCircle(5); Re.showArea(); System.out.println("实现接口运算"); doubleL=Re.getDiagonal(); doubleS=Re.getArea(); System.out.println("\n"); Sq.showArea(); System.out.println("实现接口运算"