20172318 2017-2018-2 《程序设计与数据结构》第4周学习总结
教材学习内容总结
这周内容多,要学习两章的内容,实例主要是第四章的Die和Accont类以及第七章的RationNumber,Student,Address,Question类等
教材学习中的问题和解决过程
- 问题1:对于toString不理解
- 问题1解决方案:发现这个方法与用println显示是紧密相连的,定义一个toString方法可以让println方法显示所定义对象想要的信息
- 问题2:对RationNumber类中reduce不理解
- 问题2解决方案:通过注释以及结合代码了解到reduce方法让分数返回最简形式
代码调试中的问题和解决过程
- 问题1:isantique方法使用Boolean值,但对于这个值的使用方法不清楚
问题1解决方案:
- 问题2:对于7.4中的误差寻找不到有效的表示方法
问题2解决方案:
代码托管
上周考试错题总结
- 错题1
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
方法决定行为 - 错题2
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 - 错题3
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”用于控制继承,与封装没有任何关系。 - 错题4
Consider a sequence of method invocations as follows: main calls m1, m1 calls m2, m2 calls m3 and then m2 calls m4, m3 calls m5. If m4 has just terminated, what method will resume execution?
A . m1
B . m2
C . m3
D . m5
E . main
一旦方法终止,控制就会使用调用该方法的方法恢复。在这种情况下,m2调用m4,因此当m4终止时,m2恢复。 - 错题5
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
实例数据是组成该类的实体,可能是任何可用的类型,无论是原始的还是对象的,可能是公有的还是私有的。通过使用对象作为实例数据,它允许将类构建在其他类之上。这种关系中,类拥有其他类的实例数据,称为has-a关系。 - 错题6
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
reduce方法调用gcd方法,其中一个方法是从构造函数以外的方法调用的。 - 错题7
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
声明构造函数的任何类型都是无效的 - 错题8
Java methods can return more than one item if they are modified with the reserved word continue, as in public continue int foo( ) { ... }
A . true
B . false
所有的Java方法都返回一个单项
其他(感悟、思考等,可选)
学习两章任务艰巨,不能像往常那样很轻松的完成任务,因此必须合理分配时间完成作业
学习进度条
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 5000行 | 30篇 | 400小时 | |
第一周 | 128/128 | 1/1 | 12/12 | |
第二周 | 212/340 | 1/2 | 18/30 | |
第三周 | 206/546 | 1/3 | 20/50 | |
第四周 | 483/1029 | 2/5 | 40/90 |