实现Comparable接口的Circle类

}

public double getPerimeter(){ }

public void printCircle(){ }

System.out.println(\+getDateCreated()+\return 2*radius*Math.PI;

radius is\+radius);

3) Rectangle.java

package yuan1;

public class Rectangle extends GeometricObject{

private double width; private double height; public Rectangle(){ }

public Rectangle(double width,double height){ }

public Rectangle(double width,double height,String color,boolean filled){ }

public double getWidth(){ }

public void setWidth(double width){ }

public double getHeight(){ }

public void setHeight(double height){ }

public double getArea(){ }

public double getPerimeter(){ }

return 2*(width+height); return width*height; this.height=height; return height; this.width=width; return width; this.width=width; this.height=height; setColor(color); setFilled(filled); this.width=width; this.height=height;

16

}

4) TestGeometricObject.java

package yuan1;

public class TestCircleRectangle { }

public static void main(String[]args){ }

Circle circle=new Circle(1);

System.out.println(\+circle.toString()); System.out.println(\+circle.getRadius()); System.out.println(\+circle.getArea());

System.out.println(\+circle.getDiameter()); Rectangle rectangle=new Rectangle(2,4);

System.out.println(\+rectangle.toString()); System.out.println(\+rectangle.getArea());

System.out.println(\+rectangle.getPerimeter());

七、使用说明与运行结果截图 a、 运用继承和多态

b、运用继承和多态

17

八、实践总结

从本次实验中我发现了我有很多不足的地方,但是我可以从中

学到很多很多的东西,巩固了以前所学过的知识,在实验的过程中遇到问题,但在课本、同学和老师的帮助下解决,从而发现了自己的不足之处,对以前所学过的知识理解得不够深刻,掌握得不够牢固,

通过本次实验把以前所学过的知识重新温故,我掌握了类的定义,对象的创建;掌握实现封装、继承、多态的方法,掌握各种修饰符的使用;掌握将对象数组作为方法的参数和返回值;掌握抽象类与接口的概念及实现,理解动态绑定机制;掌握通过组合与继承,实现代码可复用。

18

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4