[整理版]Java功课总结.pptVIP

  • 9
  • 0
  • 约1.22万字
  • 约 41页
  • 2018-06-29 发布于浙江
  • 举报
[整理版]Java功课总结

Java作业总结 宫良伟 孙俊忠 王庆国 赵正平 作业情况批改及总结情况 宫良伟 第7次作业,第一次上机实习 孙俊忠 第2,5次作业 王庆国 第3,6次作业,第三次上机实习 赵正平 第1,4次作业,第二次上机实习 第二次作业 Chapter8 Object-based programming 8.3 Rational class for performing arithmetic with fraction //充分利用数学运算的性质,复用代码, 8.8 Create a class Rectangle (attribute:length, width) (Method: perimeter, area) (Method: getlength, getwidth) 第二次作业 8.9 Rectangle Point point=new Point(x,y) 矩形的初始化 float[] b={x1,y1,x2,y2,x3,y3,x4,y4}; myRectangle myRet= new myRectangle (b); //函数的参数有多个且类型相同时,考虑用数组的方式传递参数 画图的Graphics 类 Graphics 是一个抽象类,虽然也有构造函数,我们无法直接使用它,而必须用Component 类的getGraphics method去取得组件上的画布,然后才能拿来画图,但是有一点要注意,就是组件此时必须为可视的状态,否则, getGraphics 将返回null public class GraphicsTest extends Frame{ public static void main(String args[]){ GraphicsTest test = new GraphicsTest(); test.setsize(300,300); test.setVisible(true); Graphics g = test.getGraphics(); g.drawLine(x1,y1,x2,y2); //画图的方法 ………………………………………………………………………………….. } } 第二次作业 8.10画矩形的方法 方法一 g.drawRect(x,y,width,length); 只能画出水平方向上的矩形 第三次作业 Object-oriented Programming 9.11,9.15,9.20 涉及到object_oriented programmer 的基本概念 主要问题是不清楚composition 与 inheritance 之间的区别与联系 Composition 当我们定义一个Class后,我们在定义其他Class时使用它,由于你在定义新的类时用到已有的类,我们称这种用法为Composition。 Composition 可以认为是一种“拥有”的关系,inheritance 是一种“像”的关系。 在什么情况下用composition或inheritance呢?当我们在创建一个新的CLASS时, 如果和已有 的CLASS的对象是一种拥有关系,尤其是新的CLASS只是用到已有 类的对象的实现功能,而且 这些功能并不要对外发布时,我们用composition更合适。即reusing the implementation。 public class Point { private double x, y; // coordinates of the Point public Point( double a, double b ) { setPoint( a, b ); } public void setPoint( double a, double b ) { x = a; y = b; } public String toString() { return [ + x + , + y + ]; } } public class Square { private double side; private Point p; // composition public Square() { this( 0.0, 0.0, 0.0 ); } public Square( double s, double a, double b ) { p = new Point( a, b ); // instantiate point object setSide( s ); public String toS

文档评论(0)

1亿VIP精品文档

相关文档