zoukankan      html  css  js  c++  java
  • 20172327 2017-2018-2 《程序设计与数据结构》第四周学习总结

    20172327 2017-2018-2 《程序设计与数据结构》第四周学习总结

    教材学习内容总结

    第4章

    • 类结构的定义和概念
    • 对象的属性和操作
    • 实例数据
    • 方法定义的结构
    • 构造方法的结构和用途

    第7章

    • 软件设计的主要问题
    • 程序所需要的类和对象
    • 静态变量与静态方法
    • 类间关系中的依赖,聚合
    • this引用
    • 接口:Comparable,Iterator
    • 枚举类型
    • 方法分解,参数的传递方式。

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

    问题1:Java接口有什么作用

    分析:

    下面是我从网上查到的一个博客,感觉说的还是挺全的。

    • 4点关于JAVA中接口存在的意义:
    • 1、重要性:在Java语言中, abstract class 和interface 是支持抽象类定义的两种机制。正是由于这两种机制的存在,才赋予了Java强大的 面向对象能力。
    • 2、简单、规范性:如果一个项目比较庞大,那么就需要一个能理清所有业务的架构师来定义一些主要的接口,这些接口不仅告诉开发人员你需要实现那些业务,而且也将命名规范限制住了(防止一些开发人员随便命名导致别的程序员无法看明白)。
    • 3、维护、拓展性:比如你要做一个画板程序,其中里面有一个面板类,主要负责绘画功能,然后你就这样定义了这个类。可是在不久将来,你突然发现这个类满足不了你了,然后你又要重新设计这个类,更糟糕是你可能要放弃这个类,那么其他地方可能有引用他,这样修改起来很麻烦。如果你一开始定义一个接口,把绘制功能放在接口里,然后定义类时实现这个接口,然后你只要用这个接口去引用实现它的类就行了,以后要换的话只不过是引用另一个类而已,这样就达到维护、拓展的方便性。
    • 4、安全、严密性:接口是实现软件松耦合的重要手段,它描叙了系统对外的所有服务,而不涉及任何具体的实现细节。这样就比较安全、严密一些(一般软件服务商考虑的比较多)。

    代码学习中的问题和解决过程

    问题1:在pp4.7的过程中,出现了程序运行出来全部为null的情况。下面是我当时的情况


    分析:解决过程是通过同学的帮助,发现我将形式参数和变量名输成相同值了,所以程序里边混乱,当我预习到第七章时,我发现我可以用This来处理这样的问题。


    问题2:在编写MultiSphere过程中,出现了下面的错误;

    分析:这个问题我后来对比同学的,发现我前面的输入语法有问题。

    上周考试错题总结

    • 第一题: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

    • 分析这些方法指示对象在传递消息时的反应方式。 每条消息都作为一个方法实现, 该方法是传递消息时执行的代码。 构造函数是这些方法之一, 但所有方法都组合在一起来决定行为。 可见性修饰符会间接影响对象的性能。

    • 第二题:Which of the following reserved words in Java is used to create an instance of a class?
      A .class
      B .public
      C .public or private, either could be used
      D .import
      E .new

    • 分析:保留字 "new " 用于实例化对象, 即创建类的实例。 新语句后面跟着类的名称。 这将调用类的构造函数。 例子: Car x = new Car ();将创建一个新的汽车实例, 并设置变量 x。

    • 第三题: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

    • 分析:封装意味着该类同时包含操作数据所需的数据和方法。 为了正确保存封装, 实例数据不应直接从类外部访问, 因此实例数据是私有的, 并且定义了方法来访问和操作实例数据。 此外, 访问和操作实例数据的方法将被公开, 以便其他类可以使用该对象。 保留字 "final " 用于控制继承, 与封装无关。

    • 第四题:If a method does not have a return statement, then
      A .it will produce a syntax error when compiled
      B .it must be a void method
      C .it can not be called from outside the class that defined the method
      D .it must be defined to be a public method
      E .it must be an int, double, float or String method

    • 分析:所有的方法都是隐含的返回的东西, 因此必须有一个返回语句。 但是, 如果程序员希望编写一个不返回任何内容的方法, 因此不需要返回语句, 则它必须是 void 方法 (标头具有 "void" 作为返回类型的方法)。

    • 第五题: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

    • 分析:实例数据是构成类的实体, 并且可以是任何可用的类型 (无论是基元还是对象), 并且可能是公共的还是私有的。 通过使用对象作为实例数据, 它允许将类构建在其他类上。 类具有其他类的实例数据的这种关系称为 "已有" 关系。

    • 第六题: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

    • 分析:声明为私有的类的所有项只能由该类中的实体访问, 无论它们是实例数据还是方法。 在这种情况下, 由于这两种方法只从理性的其他方法 (包括构造函数) 调用, 因此它们被声明为私有, 以更大程度地促进信息隐藏。 请注意, 答案 C 不是正确的答案, 因为缩减方法调用 gcd 方法, 因此从构造函数以外的方法调用其中的一个方法。

    • 第七题: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

    • 分析:公共、私有、受保护的控制变量和方法的可见性。 最终控制变量、方法或类是否可以进一步更改或重写不可见性。 静态控制变量或方法是否与类或类本身的实例关联。

    • 第八题: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

    • 分析:声明具有任何类型甚至无效的构造函数是一种语法冲突, 因此您将收到语法错误。

    • 第九题:Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.
      A .true
      B .false

    • 分析:问题有两个定义颠倒了。 形式参数是在方法标头中出现的, 实际参数是方法调用中的参数 (传递给方法)。

    • 第十题:Defining formal parameters requires including each parameters type.
      A .true
      B .false

    • 分析:为了让编译器检查方法调用是否正确, 编译器需要知道正在传递的参数的类型。 因此, 所有的正式参数 (在方法头中定义的) 必须包括它们的类型。 这是使 Java 成为强类型语言的一个元素。

    • 第十一题:Every class definition must include a constructor.
      A .true
      B .false

    • 分析:Java 允许在没有构造函数的情况下定义类, 但是, 在这种情况下使用的是默认构造函数。

    • 第十二题:During program development, software requirements specify
      A .how the program will accomplish the task
      B .what the task is that the program must perform
      C .how to divide the task into subtasks
      D .how to test the program when it is done
      E .all of the above

    • 分析:规范阶段是了解手头的问题, 以便程序员能够确定需要做些什么来解决这个问题。 上面列出的其他工作是设计阶段 (A、C) 和测试阶段 (D) 的一部分。

    • 第十三题:Static methods cannot
      A .reference instance data
      B .reference non-static instance data
      C .reference other objects
      D .invoke other static methods
      E .invoke non-static methods

    • 分析:静态方法是类本身的一部分, 而不是实例化对象的方法, 因此静态方法在类的所有实例化对象之间共享。 由于静态方法是共享的, 因此它无法访问非静态实例数据, 因为所有非静态实例数据都是特定于实例化对象的。 静态方法可以访问静态实例数据, 因为与方法类似, 实例数据在类的所有对象之间共享。 静态方法还可以访问传递给它的参数。

    • 第十四题:Inheritance through an extended (derived) class supports which of the following concepts?
      A .interfaces
      B .modulary
      C .information hiding
      D .code reuse
      E .correctness

    • 分析:通过扩展类并从它继承, 新类不必重新实现任何继承的方法或实例数据, 从而节省了程序员的精力。 因此, 代码重用是通过将他人的代码扩展为您的需要而重用其他人的密码的能力。

    • 第十五题:In order to implement Comparable in a class, what method(s) must be defined in that class?
      A .equals
      B .compares
      C .both lessThan and greaterThan
      D .compareTo
      E .both compares and equals

    • 分析:可比较类要求 compareTo 方法的定义, 它将比较两个对象并确定一个是否等于另一个, 或者如果一个小于或大于另一个, 并以负 int、0或正整数响应。 由于 compareTo 的响应与0如果两个对象相等, 则不需要定义等号方法。

    • 第十六题:Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length( ), in order to use the Math class, you pass messages directly to the class name, as in Math.abs( ) or Math.sqrt( ).
      A .true
      B .false

    • 分析:数学类使用被称为静态方法 (或类方法) 的方法, 通过将消息直接传递到类名本身而不是类的对象来调用。

    • 第十七题:Interface classes cannot be extended but classes that implement interfaces can be extended.
      A .true
      B .false

    • 分析:任何类都可以扩展, 无论它是接口、实现接口还是两者都不是。 唯一的例外情况是, 如果该类被显式修改为 "final ", 在这种情况下, 不能扩展。

    • 第十八题:Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.
      A .true
      B .false

    • 分析:问题有两个定义颠倒了。 形式参数是在方法标头中出现的, 实际参数是方法调用中的参数 (传递给方法)。

    • 第十九题:In black-box testing, the tester should already know something about how the program is implemented so that he/she can more carefully identify what portion(s) of the software are leading to errors.
      A .true
      B .false

    • 分析:在黑盒测试中, 测试人员不应该知道软件是如何实现的。 实质上, 软件是一个具有输入和输出的黑箱, 程序的机制是不透明的。 如果测试人员确实知道程序是如何工作的, 那么测试人员的测试用例可能会有偏差。 如果测试人员知道程序的工作原理, 那么测试就被称为玻璃盒测试。

    代码托管


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

    进入第二周,有点难,程序的样子和上一周有所改变,但要打的代码更多了,发现时间有点不够用,感觉这一周学的状态并不好,所以下一周会花更多的时间在Java的学习中。

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
    目标 5000行 30篇 400小时
    第一周 95/95 1/1 18/18
    第二周 515/620 1/2 22/40
    第三周 290/910 1/3 20/60
    第四周 1741/2651 1/4 30/84

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

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

    • 计划学习时间:20小时

    • 实际学习时间:30小时

    • 改进情况:有点

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

    参考资料

  • 相关阅读:
    leetcode206题实现反转链表(c语言)
    V22017编写C/C++时没有与参数列表匹配的重载函数实例
    3DMAX导出到Unity坐标轴转换问题
    ihandy2019笔记编程真题
    模糊数学中合成算子的计算方法
    点击Button按钮实现页面跳转
    做HTML静态页面时遇到的问题总结
    pip换源
    Python正课146 —— DRF 进阶7 JWT补充、基于权限的角色控制、django缓存
    Python正课145 —— DRF 进阶6 自定制频率、接口文档、JWT
  • 原文地址:https://www.cnblogs.com/mrf1209/p/8718652.html
Copyright © 2011-2022 走看看