20172324《程序设计与数据结构》第四周学习总结

20172324《程序设计与数据结构》第四周学习总结

教材学习内容总结

  • 类结构的定义和概念
  • 利用实例数据建立对象状态
  • 可见性修饰符作用在方法和数据上的效果
  • 方法参数(形参和实参)和返回值
  • 类之间的关系(依赖、聚合)
  • 建立形式化对象接口的方法

1332976-20180404171241481-1346920245.jpg

1332976-20180404170928431-491605268.jpg

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

  • 问题1:形式参数和实际参数的区别
  • 问题1解决方案:这个图解决了我所有的疑惑。1332976-20180404170946973-2133473307.png
  • 问题2:.addInterest是什么意思…
  • 问题2解决方案: 因为之前查如何return多个值的时候就看到过add,这里也以为是为了返回多个值,查过之后才知道原来add属于list方法,可以add任何类型对象,在这里的对象就是利息。

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

  • 问题1:这一周的代码似乎都是要先定义后才能编译,在编译Transactions时,
    deposit处提示Create method ‘deposit’in ‘Account’,无法运行。
    所以我就在Account中定义了deposit,可是运行的时候又出现了“缺少返回语句”的错误提示。
  • 问题1解决方案:首先,在Account中定义deposit时需要输入命令public double deposit(double v){},然后在括号里输入return v;这样定义的deposit才会返回 Transactions中。
  • 问题2:在做习题4.9的时候int了两个faceValue的值分别是faceValue1和faceValue2,但是在return的时候就发现return只能返回一个值。
  • 问题2解决方案: 看题目的时候没有理解由两个Die对象组成是什么意思,所以由重新定义了faceValue1 = (int)(Math.random()*MAX)+1;faceValue = (int)(Math.random()*MAX)+1;但是return的话就只能返回一个值,上网搜索解决方案是时看到一种add的方法,先add两个值,在return处用加号连接,最后再用substring分开。不过说实话,我试过之后的结果就是每一个骰子都会掷出相同的两个值,没有成功。最后是直接用之前定义好的roll方法,将f1和f2都用.roll();的方法直接代替之前的定义,return的时候再用加号连接就不会出现一个值反复出现两遍的问题了。

代码托管

1332976-20180404171019625-447864087.png
(statistics.sh脚本的运行结果截图)

上周考试错题总结

  1. If two variables contain aliases of the same object then
    A .the object may be modified using either alias
    B .the object cannot be modified unless there's but a single reference to it
    C .a third alias is created if/when the object is modified
    D .the object will become an "orphan" if both variables are set to null
    E .answers A and D are correct

如果两个变量的别名是一样的,这个对象也许会占用另外一个地址。如果两个变量都设置为 null, 则该对象将成为 "孤儿" 。根据定义, 别名提供了可以修改对象的方法 (别名类似于指针)。如果两个变量都设置为 null, 则任何变量都不会引用该对象 (通过任何别名), 并且它确实成为 "孤儿", 并且它将在某个时候成为垃圾被收集。

  1. Which properties are true of String objects?
    A . Their lengths never change
    B . The shortest string has zero length
    C . Individual characters within a String may be changed using the replace method
    D . The index of the first character in a string is one
    E . Only A and B are true

字符串对象的哪些属性是正确的? 他们的长度永远不会改变,最短的字符串长度为零。字符串是不可变的。这意味着, 一旦创建了字符串对象, 就不能更改它。因此, 字符串的长度在创建后不会更改。最短长度字符串为 "", 引号之间没有字符, 因此长度为零。

  1. What happens if you attempt to use a variable before it has been initialized?
    A .A syntax error may be generated by the compiler
    B.A runtime error may occur during execution
    C .A "garbage" or "uninitialized" value will be used in the computation
    D .A value of zero is used if a variable has not been initialized
    E.Answers A and B are correct如果在初始化之前尝试使用变量, 会发生什么情况? 编译器可能生成语法错误,执行期间可能发生运行时

错误。编译器多次能够检测到未初始化变量的尝试使用, 在这种情况下会产生语法错误。如果编译器使用转义检测, 则在使用时会发生运行时错误。

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

点运算符的功能是什么?当给定对对象的引用时, 它允许一个访问对象中的数据,当给定对象的引用时, 它允许在对象内调用方法。

  1. In Java, "instantiation" means
    A . noticing the first time something is used
    B . creating a new object of the class
    C . creating a new alias to an existing object
    D . launching a method
    E . none of the above

在 Java 中, "实例化" 意味着 创建类的新对象

  1. Consider the following two lines of code. What can you say about s1 and s2?
    String s1 = "testing" + "123";
    String s2 = new String("testing 123");
    A . s1 and s2 are both references to the same String object
    B . the line declaring s2 is legal Java; the line declaring s1 will produce a syntax error
    C . s1 and s2 are both references to different String objects
    D . s1 and s2 will compare "equal"
    E . none of the above

请考虑下面两行代码。关于 s1 和 s2, 你能说些什么?字符串 s1 = "测试" + "123";
字符串 s2 = 新字符串 ("测试 123"); s1 和 s2 都是对不同字符串对象的引用。s1 是字符串引用, 它被初始化为字符串 "testing123"。s2 是字符串引用, 它被初始化为字符串 "测试 123"。请注意 "测试" 和 "123" 之间的间距。所以这两个字符串是不相等的。

  1. An "alias" is when
    A . two different reference variables refer to the same physical object
    B . two different numeric variables refer to the same physical object
    C . two different numeric variables contain identical values
    D . two variables have the same names
    E . none of the above

“别名" 是指两个不同的引用变量引用相同的物理对象。

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

字符串类的 compareTo 方法如果两个字符串相同, 则生成0。

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

与数学相比, 随机类的伪随机数生成器的优势随机方法, 是可以创建几个随机数生成器、可以在一个范围内生成随机整数、浮点和整数、可以对随机生成器进行初始化和重新初始化、所有随机数发生器的效率是相同的。

  1. The advantages of the DecimalFormat class compared with the NumberFormat class include
    A . precise control over the number of digits to be displayed
    B . control over the presence of a leading zero
    C . the ability to truncate values rather than to round them
    D . the ability to display a % automatically at the beginning of the display
    E . only A and B

与 NumberFormat 类相比, DecimalFormat 类的优点包括精确控制要显示的位数 控制前导零的存在。

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

这两种设置字符串的方法产生相同的结果: a) 字符串字符串 = 新字符串 ("123.45");b) 字符串字符串 = "" + 123.45; (true)

  1. If you need to import not only the top-level of a package, but all its secondary levels as well, you should write: import package..;
    A . true
    B . false

如果您不仅需要导入包的顶层, 而且还要输入所有的辅助级别, 则应编写: 导入包. ;(false);导入包.

  1. The printf method within System.out is designed to ease the conversion of legacy C code into Java.
    A . true
    B . false

系统中的 printf 方法是为了简化旧式 C 代码转换为 Java 而设计的。(true)

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

包装类的名称只是原始数据类型的名称, 但具有初始大写字母。(false)对于大多数包装类来说, 这是正确的, 但 int (整数) 和 char (字符) 是错误的。

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

这两章其实讲的内容差不多,我感觉第七章就是第四章更为详细的解释,但是这些概念仍然很模糊,我最后就是把书上的很多概念整理在本子上以后才能明白得比较透彻一点…但是不得不说,看不懂,真的不懂,感觉很多概念都是一样的,很模糊,还有一个问题就是感觉读不懂题目,就比如那个可以使用两个Die类,我完全不能理解…?

学习进度条

代码行数(新增积)博客量(新增积)学习时间(新增积)重要成长
目标5000行30篇400小时
第一周200/2002/220/20
第二周329/5002/418/38
第三周619/10003/722/60
第四周817/17344/738/60

参考资料

转载于:https://www.cnblogs.com/amberR/p/8718302.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值