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

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

教材学习内容总结

  • 第五章
    • 控制程序执行流程的语句分为两类:条件语句(又称为选择语句)和循环语句。
    • 相等性、关系和逻辑运算符的运用
    • if语句(条件语句),可使用语句块,可嵌套。
      • 格式:if(布尔表达式){一条或一组语句}
    • if-else语句。
      • 格式:if(布尔表达式){一条或一组语句} else{一条或一组语句}
      • else会与它最前面未匹配的if语句匹配。
    • while语句(循环语句),可嵌套,能完成无限循环。
    • 数据比较。主要讲了浮点数比较和字符串比较两部分。
      • 格式:while(布尔表达式){语句或语句块}
    • break和contin语句。
      • break语句的作用可简述为“跳出”循环。
      • continue语句的作用与break相似,但若循环再次进行,布尔值为true时仍会继续进行循环。
    • 迭代器和ArrayList类,大概看懂书上的内容,应用感觉还不是很会。
  • 第六章
    • switch语句。
      • 格式:switch(布尔表达式){case 1;break;case2 break;...default}
      • break和default都不是必须要有的。
      • 表达式的运算结果必须是char、byte、short、int或String型。
    • 条件运算符。
      • 格式:(布尔条件?表达式:表达式)
      • 可读性不如if-else语句,作用上与之相似。
    • do语句(循环语句)。
      • 格式:do{语句或语句块}while(布尔表达式)
      • 与while语句作用相似,不同点在于do语句至少执行一次。
    • for语句(循环语句)。
      • 格式:for(初始化;布尔表达式;增量部分){语句}
      • 增量部分既可递增也可递减。
      • 与前两个循环语句作用相似,建议在知道具体循环次数时使用。

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

  • 问题1:第五章自测题SR5.11的a做的时候结果与答案不符
  • 问题1解决方案:自己把代码敲出来运行了一下,结果仍然与答案不符,答疑之后确定是答案错误。
  • 问题2:做例5.9时不清楚another.equalsIgnoreCase("y")是干嘛的
  • 问题2解决方案:查书第76页String类提供的一些方法中说该方法的用法是“如果本对象字符串与str对象字符串相同(不区分大小写),返回真,否则返回假。”
  • 问题3:第五章自测题SR5.29做出来又与答案不符_(:з」∠)_
  • 问题3解决方案:再把前面的内容看了一遍发现是自己看书太粗糙,主要错过的两个要点是:1.ArrayList的索引值从0开始。2.remove方法的作用是删除列表指定索引处那个元素并【返回】它。

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

  • 问题1:git push失败,让先git pull,而git pull又发生错误(很遗憾这里忘记截图了...)
  • 问题1解决方案:先把之前的东西备份了一份,尝试了很多次之后选择重新建一个directory,使用git clone把码云上的东西重新弄回来,新的可以使用git push但旧的还是不行_(:з」∠)_ 不过没多大问题就是新的目录里的代码量又从0开始统计了...解决的方法是每次在这个新目录里编辑完之后全部复制到旧目录里来统计代码量_(:з」∠)_
  • 问题2:PP5.7最后输赢和平局的统计结果总是不对
  • 问题2解决方案:询问了张昊然同学后知道了是因为if语句后没把那些表达式归到一个语句块里,导致“++”不论什么情况都会运行。之前的修改过的

代码托管


commit截图

上周考试错题总结

  • 错题1:The relationship between a class and an object is best described as
    • A . classes are instances of objects
    • B . objects are instances of classes
    • C . objects and classes are the same thing
    • D . classes are programs while objects are variables
    • E . objects are the instance data of classes
  • 原因及理解情况:一词之差,“实例”和“实例数据”,实例被称为对象,而实例数据...我在网上根本查不到这个东西_(:з」∠)_
  • 错题2: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与分装无关。
  • 错题3: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
  • 错题4: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
  • 原因及理解情况:声明为私有的类的所有项只能由该类中的实体访问,无论它们是实例数据还是方法。
  • 错题5: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
  • 原因及理解情况:以后要改掉这个稍微看不懂题,看到E选项是个总结性的就选它的毛病。本题网页上的答案是错的,正确答案是D,构造函数没有void,加了之后会变成普通方法。
  • 错题6:Every class definition must include a constructor.
    • A . true
    • B . false
  • 原因及理解情况:本题意思是必须编译一个,但在编译时系统会自动产生一个空的构造函数。
  • 错题7: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
  • 原因及理解情况:实例数据中包含静态和非静态的,只能引用静态的,非静态的必须声明(new)之后才能用。
  • 错题8:Inheritance through an extended (derived) class supports which of the following concepts?
    • A . interfaces
    • B . modulary
    • C . information hiding
    • D . code reuse
    • E . correctness
  • 原因及理解情况:概念性问题。
  • 错题9:The goal of testing is to
    • A . ensure that the software has no errors
    • B . find syntax errors
    • C . find logical and run-time errors
    • D . evaluate how well the software meets the original requirements
    • E . give out-of-work programmers something to do
  • 原因及理解情况:当时看的时候英语理解有问题。软件测试的作用在书上第194页。
  • 错题10:Interface classes cannot be extended but classes that implement interfaces can be extended.
    • A . true
    • B . false
  • 原因及理解情况:对于接口,可以继承,一个类可以继承多个接口,不论类是否扩展都能继承。

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

  • 首先这星期最大的一个感悟就是做课后自测题真的非常非常重要!以前基本都是一晃而过或者做的很少_(:з」∠)_但本周认真做的时候发现很多问题都是在做自测题的时候发现的,并且做自测题真的是对前面知识掌握程度的一个非常好的考核。除此之外,感觉自己越往后学前面忘得越多,所以我决定从这周开始重新从第一章开始看课本,计划从下周开始在博客中记录重新看课本的进度。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第一周 120/120 1/1 9/9
第二周 246/366 1/2 9/18
第三周 785/1121 2/4 15/33
第四周 615/1736 1/5 20/53
第五周 1409/2645 1/6 24/77
  • 计划学习时间:18小时
  • 实际学习时间:24小时
  • 改进情况:本来看着这周内容少觉得花的时间不会多,没想到在PP5.3和PP5.7上花费了暴多时间。另外,在动车上敲代码的感觉很不错_(:з」∠)_

参考资料

posted @ 2018-04-10 21:57  框框框  阅读(279)  评论(5编辑  收藏  举报