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

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

教材学习内容总结

1、循环的使用
2、UML 建模
3、方法重载
4、类的封装、继承、聚合等
5、迭代器 ( Iterator ) 及其方法的简单使用
6、接口 ( Interface ) 的编写与使用

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

  • 问题1:字符不能通过nextChar()输入
  • 问题1解决方案:Scanner类中没有nextChar()方法,可使用charAt(int)返回指定位置的字符。

  • 问题2:git push 推送代码时显示 “ unable to access 'xxxx': Could not resolve host : gitee.com ”
  • 问题2解决方案:经查是虚拟机网络断开所致。

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

  • 问题:格式化输出 “#.###” 当小数位最后为 0 时自动省略
  • 问题解决方案:“ # ”格式化输出不会为 0 占位,可以使用 “#.000” 。

其它问题已记录至博客 实验报告二

代码托管

(statistics.sh脚本的运行结果截图)

上周考试错题总结

  • The behavior of an object is defined by the object's
    A. instance data
    B. constructor
    C. visibility modifiers
    D. methods
    E. all of the above
    解析:The methods dictate how the object reacts when it is passed messages. Each message is implemented as a method, and the method is the code that executes when the message is passed. The constructor is one of these methods but all of the methods combine dictate the behavior. The visibility modifiers do impact the object's performance indirectly.

  • 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.

  • A class' constructor usually defines
    A. how an object is initialized
    B. how an object is interfaced
    C. the number of instance data in the class
    D. the number of methods in the class
    E. if the instance data are accessible outside of the object directly
    解析:The constructor should be used to "construct" the object, that is, to set up the initial values of the instance data. This is not essential, but is typically done. The interface of an object is dictated by the visibility modifiers used on the instance data and methods.

  • Instance data for a Java class
    A. are limited to primitive types (e.g., int, float, char)
    B. are limited to Strings
    C. are limited to objects(e.g., Strings, classes defined by other programmers)
    D. may be primitive types or objects, but objects must be defined to be private
    E. may be primitive types or objects
    解析:The instance data are the entities that make up the class and may be any type available whether primitive or object, and may be public or private. By using objects as instance data, it permits the class to be built upon other classes. This relationship where a class has instance data that are other classes is known as a has-a relationship.

  • Consider a Rational class designed to represent rational numbers as a pair of int's, along with methods reduce (to reduce the rational to simplest form), gcd (to find the greatest common divisor of two int's), as well as methods for addition, subtraction, multiplication, and division. Why should the reduce and gcd methods be declared to be private.
    A. Because they will never be used
    B. Because they will only be called from methods inside of Rational
    C. Because they will only be called from the constructor of Rational
    D. Because they do not use any of Rational's instance data
    E. Because it is a typo and they should be declared as public
    解析:All items of a class that are declared to be private are only accessible to entities within that class, whether they are instance data or methods. In this case, since these two methods are only called from other methods (including the constructor) of Rational, they are declared private to promote information hiding to a greater degree. Note that answer C is not a correct answer because the reduce method calls the gcd method, so one of the methods is called from a method other than the constructor.

  • Visibility modifiers include
    A. public, private
    B. public, private, protected
    C. public, private, protected, final
    D. public, protected, final, static
    E. public, private, protected, static
    解析: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.

  • What happens if you declare a class constructor to have a void return type?
    A. You'll likely receive a syntax error
    B. The program will compile with a warning, but you'll get a runtime error
    C. There's nothing wrong with declaring a constructor to be void
    D. The class' default constructor will be used instead of the one you're declaring
    E. None of the above
    解析:It is a syntax violation to declare a constructor with any type even void so you'll receive a syntax error.

结对及互评

点评:

  • 博客中值得学习的或问题:
    • 图文并茂,有参考资料
    • markdown 格式运用较为熟练
  • 代码中值得学习的或问题:
    • 代码格式规范,合理使用空白,便于阅读
  • 基于评分标准,我给本博客打分:14分。得分情况如下:
    • 1、正确使用Markdown语法(加1分)
    • 2、模板中的要素齐全(加1分)
    • 3、教材学习中的问题和解决过程(2分)
    • 4、代码调试中的问题和解决过程(1分)
    • 5、本周有效代码超过300分行的(加2分)
    • 6、其他加分:
      • 感想,体会不假大空的加1分
      • 进度条中记录学习时间与改进情况的加1分
      • 有动手写新代码的加1分
      • 代码Commit Message规范的加1分
      • 错题学习深入的加1分
      • 点评认真,能指出博客和代码中的问题的加1分
      • 结对学习情况真实可信的加1分
  • 参考示例

点评过的同学博客和代码

  • 本周结对学习情况
    • 20182329

    • 结对学习内容
      • 使用单元测试进行代码测试
      • TDD代码测试
      • 学习使用编写类,用 public 、void 等编写、调用类的方法进行运算
      • 类与类的关系、继承、聚合、关联
      • 学习方法调用和包装方法的使用

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

经过这两周的学习实践,我逐渐体会到上学期学习 C 语言所打下的基础,其实 C 语言与 Java 语言虽有不同但也有相通之处,其精髓需要更加细致的学习以逐步体会。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 10000行 30篇 400小时
第一周 109/109 2/2 28/28 学习了Java的基本语法格式,熟练使用 Linux Bash 命令
第二周 550/659 1/3 23/51 学习掌握JDB调试命令
第三周 1028/1687 2/5 30/81 学习类的编写与使用
第四周 542/2229 2/7 22/103 学习方法重载,类的继承、聚合等

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

  • 计划学习时间:20小时

  • 实际学习时间:22小时

  • 改进情况:

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

参考资料

猜你喜欢

转载自www.cnblogs.com/lolipop2019/p/11613815.html