《数据结构与面向对象程序设计》第四周学习总结

20182304 2019-2020-1 《数据结构与面向对象程序设计》第四周学习总结

教材学习内容总结

  • 1.本章我们学习了使用并编写我们自己的类:类中有与类同名的构造方法,也可以有set,get,toSring与自己定义的方法。实例化一个对象,可通过该对象使用类里的所有方法。实例数据是每次创造一个实例后自动生成新的内存空间的变量
  • 2.uml类图 :每个类可能包含三部分内容:类名、属性、操作(方法)。UML类图有属于自己的语法,变量的类型名在变量名的后面,它们之间用冒号作为分隔符,方法的+和-表明可见性。箭头指向,表明一个类知道并以某种方法使用另一个类(调用)。
  • 3.封装概念
  • 4.可见性修饰符 :public 可从类外直接访问(一般将常量设为公有,因为它不能被随意改变,安全性可以得到保障)
    private 强制封装,不能被类外调用 protected与继承关系相关,既可以被子类调用,也保证了封装
  • 5.类中的关系:依赖(has a)、继承、聚合,this引用
  • 6.接口的概念

    教材学习中的问题和解决过程

  • 问题1:如何理解静态方法
  • 问题1解决方案:静态方法用static修饰,不用实例化类就可以调用。它不能引用类的实例中的实例变量,所以一般引用静态变量
  • 问题2:this引用有什么作用
  • 问题2解决方案:this引用能让一个对象指向自己,this引用常用来区分构造方法中的参数与对应的同名实例变量。在需要给类中的数据传参时,可以取相同的名字,只要左边加上this.引用
  • 问题3:封装的概念是什么,为什么要提倡封装
  • 问题3解决方案:对象应该是封装的,封装就是将数据与相关行为包装在一起以实现信息隐藏,既可以隐藏类的实现细节,又可以避免对类中属性的直接操作。封装实际上控制用户对类的修改和访问数据的程度,只能够通过对象提供服务的那些方法与程序其它部分进行交互,接口是封装的准确描述手段。一个类内的声明变量,应该仅由类内访问并修改,类外不应该也不能修改变量的值。

代码调试中的问题和解决过程

  • 问题1:误在get方法中传参导致程序错误
  • 问题1解决方案:通过同学的帮助,了解到get方法中不能传入参数,只能返回数据。传参应该在其它方法如set中完成
  • 问题2:在敲书上的Coin类时,一行代码count1 = (coin1.isHeads()) ? count1+1 : 0;我将count1+1敲成了count++,本来以为区别不大,程序运行时却造成了死循环

  • 问题2解决方案:count++count=count+1等价,count本身被该变了。因为上式中等式左边有count=,所以造成了死循环。而count+1不改变count的值,所以在赋值语句中可以正常使用
  • 问题3:git配置好后无法正常上传
  • 问题3解决方案:没有看清 push 后再提交,默认的是commit,需要自己手动设置一下

代码托管

上周考试错题总结

  • What is the function of the dot operator?
    • A .It serves to separate the integer portion from the fractional portion of a floating point number
    • B .It allows one to access the data within an object when given a reference to the object
    • C .It allows one to invoke a method within an object when given a reference to the object
    • D .It is used to terminate commands (much as a period terminates a sentence in English)
    • E .Both B and C are correct
    • The dot operator is appended directly after the object reference, followed by the data or method to which access is desired. In the case of data, the access may be for reading or writing. In the case of a method, the access is to allow one to invoke the method. The dot within a floating point number is a decimal point not a dot operator.
    • 理解:点运算符可以直接加在对象引用之后,然后加上要调用的方法名,也可以在给定对象的引用时访问对象中的数据。。
  • The String class' compareTo method
    • A .compares two string in a case-independent manner
    • B .yields true or false
    • C .yields 0 if the two strings are identical
    • D .returns 1 if the first string comes lexically before the second string
    • E .none of the above
    • 理解:identical为相等,没有理解英文含义导致错误。compareTo与C中的用法相似
  • The names of the wrapper classes are just the names of the primitive data types, but with an initial capital letter.
    • A .true
    • B .false
    • This is true for most of the wrapper classes, but it is false for int (Integer) and char (Character).
    • 理解:翻阅图书,可查到int的包装类为Integer,char的包装类是Character,其它类型包装类为首字母大写
  • The advantage(s) of the Random class' pseudo-random number generators, compared to the Math.random method, is that
    • A .you may create several random number generators
    • B .the generators in Random are more efficient than the one in Math.random
    • C .you can generate random ints, floats, and ints within a range
    • D .you can initialize and reinitialize Random generators
    • E .all but answer B
    • The efficiency of all the random number generators are the same. The advantages of Random generators over Math.random include all the other properties.
    • 理解:效率是一样的
  • These two ways of setting up a String yield identical results:
  • a) String string = new String("123.45"); b) String string = "" + 123.45;
    • A .true
    • B .false
    • 理解:""也是字符串,+可以自动连接字符串,这样后面的数字也以字符串的形式被赋给了string,两者等价
  • In order to preserve encapsulation of an object, we would do all of the following except for which one?
    • A .Make the instance data private
    • B .Define the methods in the class to access and manipulate the instance data
    • C .Make the methods of the class public
    • D .Make the class final
    • E .All of the above preserve encapsulation
    • Encapsulation means that the class contains both the data and the methods needed to manipulate the data. In order to preserve encapsulation properly, the instance data should not be directly accessible from outside of the classes, so the instance data are made private and methods are defined to access and manipulate the instance data. Further, the methods to access and manipulate the instance data are made public so that other classes can use the object. The reserved word "final" is used to control inheritance and has nothing to do with encapsulation.
    • 理解 :D一定是错误的,如果把类设置成final,它就不能被重写,子类一直都会是抽象类,不能实例化
  • Having multiple class methods of the same name where each method has a different number of or type of parameters is known as
    • A .encapsulation
    • B .information hiding
    • C .tokenizing
    • D .importing
    • E .method overloading
    • When methods share the same name, they are said to be overloaded. The number and type of parameters passed in the message provides the information by which the proper method is called.
    • 理解:错误原因是因为对书中类型知识点理解不足
  • Visibility modifiers include
    • Public, private, protected control the visibility of variables and methods. Final controls whether a variable, method, or class can be further changed or overridden not visibility. Static controls whether a variable or method is associated with instances of a class or the class itself.
  • The following method header definition will result in a syntax error: public void aMethod( );
    • A .true
    • B .false
    • The reason for the syntax error is because it ends with a ";" symbol. It instead needs to be followed by { } with 0 or more instructions inside of the brackets. An abstract method will end with a ";" but this header does not define an abstract method.
    • 理解:首先,方法后不能有冒号。其次,它后面应该有一个大括号
  • Every class definition must include a constructor.
    • A .true
    • B .false
    • Java allows classes to be defined without constructors, however, there is a default constructor that is used in such a case.
    • 理解:可以不定义,它会默认生成一个构造方法

结对及互评

评分标准

  1. 正确使用Markdown语法(加1分):
    • 不使用Markdown不加分
    • 有语法错误的不加分(链接打不开,表格不对,列表不正确...)
    • 排版混乱的不加分
  2. 模板中的要素齐全(加1分)
    • 缺少“教材学习中的问题和解决过程”的不加分
    • 缺少“代码调试中的问题和解决过程”的不加分
    • 代码托管不能打开的不加分
    • 缺少“结对及互评”的不能打开的不加分
    • 缺少“上周考试错题总结”的不能加分
    • 缺少“进度条”的不能加分
    • 缺少“参考资料”的不能加分
  3. 教材学习中的问题和解决过程, 一个问题加1分

  4. 代码调试中的问题和解决过程, 一个问题加1分

  5. 本周有效代码超过300分行的(加2分)
    • 一周提交次数少于20次的不加分
  6. 其他加分:
    • 周五前发博客的加1分
    • 感想,体会不假大空的加1分
    • 排版精美的加一分
    • 进度条中记录学习时间与改进情况的加1分
    • 有动手写新代码的加1分
    • 课后选择题有验证的加1分
    • 代码Commit Message规范的加1分
    • 错题学习深入的加1分
    • 点评认真,能指出博客和代码中的问题的加1分
    • 结对学习情况真实可信的加1分
  7. 扣分:
    • 有抄袭的扣至0分
    • 代码作弊的扣至0分
    • 迟交作业的扣至0分

点评模板:

  • 博客中值得学习的或问题:
    • xxx
    • xxx
    • ...
  • 代码中值得学习的或问题:
    • xxx
    • xxx
    • ...
  • 基于评分标准,我给本博客打分:XX分。得分情况如下:xxx

  • 参考示例

点评过的同学博客和代码

  • 本周结对学习情况
    • 20182302
      • 结对学习内容
      • 学习接口的概念与具体操作
      • 理解类的定义与封装
      • 调试实验程序中的编译错误
  • 上周博客互评情况

其他(感悟、思考等,可选)

  • 在测试后,我发现自己只对教材有大概理解,很多知识点细节还是陌生的,存在着很大的提升空间
  • 从第五章开始,Java的学习难度是比较大的,需要花费更多时间精力学习

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第一周 200/200 2/2 20/20
第二周 300/500 2/4 18/38
第三周 500/1000 3/7 22/60
第四周 300/1300 2/9 35/100

尝试一下记录「计划学习时间」和「实际学习时间」,到期末看看能不能改进自己的计划能力。这个工作学习中很重要,也很有用。
耗时估计的公式:Y=X+X/N ,Y=X-X/N,训练次数多了,X、Y就接近了。

参考:软件工程软件的估计为什么这么难软件工程 估计方法

  • 计划学习时间:40小时

  • 实际学习时间:35小时

  • 改进情况:我会努力提高一些学习效率

(有空多看看现代软件工程 课件
软件工程师能力自我评价表
)

参考资料

猜你喜欢

转载自www.cnblogs.com/acgacg/p/11614371.html