1. 程式人生 > >20172303 2017-2018-2 《程序設計與數據結構》第5周學習總結

20172303 2017-2018-2 《程序設計與數據結構》第5周學習總結

nal b- span 使用 字符串相同 完成 sim serve 訪問

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語句後沒把那些表達式歸到一個語句塊裏,導致“++”不論什麽情況都會運行。之前的技術分享圖片[]修改過的(https://images2018.cnblogs.com/blog/1332969/201804/1332969-20180410215557332-1345099295.png)

代碼托管

技術分享圖片
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上花費了暴多時間。另外,在動車上敲代碼的感覺很不錯_(:з」∠)_

參考資料

  • 《Java程序設計與數據結構教程(第二版)》

  • 《Java程序設計與數據結構教程(第二版)》學習指導

  • 藍墨雲第三周答疑

20172303 2017-2018-2 《程序設計與數據結構》第5周學習總結