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

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

其他 形參 本周 級別 tint proc 多次 import mis

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

教材學習內容總結

  • 第四章:
    • 學會了簡單的編寫類
    • 了解了UML類圖(真的很有用!!!!)
    • 了解了return語句的用法
    • 明白了形參與實參的區別
  • 第七章:
    • 了解了軟件開發活動的過程
    • 了解了靜態變量和靜態方法
    • 了解了變量之間的依賴關系和聚合關系
    • 學會了this引用
    • 了解了接口的相關方法
    • 學會了枚舉類型的使用
    • 了解了如何測試代碼

教材學習中的問題和解決過程

  • 問題1:看到第七章時有些分不清靜態變量和實例變量
  • 問題1解決方案:自己查了相關資料:
    • 語法區別:靜態變量需要static關鍵字修飾,實例變量不需要。
    • 程序運行時的區別:靜態變量從屬於類,實例變量從屬於對象。
    • 實例變量必須創建了實例對象,其中的實例變量才會被分配空間,才能使用這個實例變量;靜態變量即類別量,只要程序加載了類的字節碼,靜態變量就會被分配空間,即可使用。
    • 綜上,實例變量必須創建對象後通過這個對象來使用,靜態變量可以直接使用類名來引用。

代碼調試中的問題和解決過程

  • 問題1:在做例4.3時,顯示的結果全是“+name”技術分享圖片
  • 問題1解決方案:修改了很多次最後發現是最後一句少加了一個引號_(:з」∠)_技術分享圖片技術分享圖片

代碼托管

技術分享圖片

上周考試錯題總結(正確為綠色,錯誤為紅色)

  • 錯題1:In Java a variable may contain
    • A . a value or a reference
    • B . a package
    • C . a method
    • D . a class
    • E . any of the above
  • 原因:沒看清題目問的是什麽
  • 理解情況:java的變量包含對實例類的值或引用。
  • 錯題2: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
  • 原因:對String的理解不足,覺得B是對的,但覺得A不對,所以沒有選E...
  • 理解情況:字符串是不可變的。這意味著一旦創建了一個字符串對象,它就不能被改變。
  • 錯題3:In the StringMutation program shown in Listing 3.1, if phrase is initialized to "Einstein" what will Mutation #3 yield if Mutation #1: mutation1 = phrase.concat(".")?
    • A . Einstein.
    • B . EINSTEIN.
    • C . XINSTXIN.
    • D . einstein.
    • E . xinstxin.
  • 原因:把題目當成了單純地一步,沒有理解它其實是類似書上例3.1中的一部分。
  • 理解情況:題目中的方法在原句的基礎上加了一個“.”,但接著之後做完的話,第三步會將所有E換為X。
  • 錯題4:Which of the following will yield a pseudorandom number in the range [ -5, +5 ) given the following:
    Random gen = new Random( );
    • A . gen.nextFloat( ) * 5
    • B . gen.nextFloat( ) * 10 - 5
    • C . gen.nextFloat( ) * 5 - 10
    • D . gen.nextInt( ) * 10 - 5
    • E . gen.nextInt(10) - 5
  • 原因:錯在了整型與浮點型的選擇上(ー`′ー)
  • 理解情況:int產生的是[-5,+4]之間的。
  • 錯題5: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
  • 原因:理解有問題。
  • 理解情況:聽老師上課講過之後知道了這兩個都是合法的,但第一個中間沒有空格。
  • 錯題6: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方法,所以不是很懂_(:з」∠)_
  • 理解情況:看過了第七章之後學會了compareTo方法,compareTo可以比較兩個數的大小,當兩個數相等時輸出“0”。
  • 錯題7:Java.text‘s NumberFormat class includes methods that
    • A . allow you to format currency
    • B . allow you to format percentages
    • C . round their display during the formatting process
    • D . truncate their display during the formatting process
    • E . A, B, C, but not D
  • 原因:我也不知道當時為什麽要選C...可能是英語理解有問題。
  • 理解情況:NumberFormat類提供了通用的數據格式化能力。
  • 錯題8: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
  • 原因:在敲這個例題的時候對B感觸很深,但A感觸不是很深
  • 理解情況:雖然DecimalFormat的確提供了比NumberFormat更多的控制,但截斷仍然通過一個或多個Math方法掌握在程序員手中。%符號將出現在顯示的末尾而不是開頭。
  • 錯題9:When comparing any primitive type of variable, == should always be used to test to see if two values are equal.
    • A . true
    • B . false
  • 原因:對==的理解不到位。
  • 理解情況: double和float不能使用==來測試。
  • 錯題10: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
  • 原因:用IDEA敲代碼的時候不認真...每一個java文件的開頭都有這句。
  • 理解情況:導入語句只能與一個*(通配符)一起使用。如果您還需要導入包的所有輔助級別,則必須明確寫出它們。
  • 錯題11:The printf method within System.out is designed to ease the conversion of legacy C code into Java.
    • A . true
    • B . false
  • 原因:在沒有查任何資料的情況下想當然地認為它是對的。
  • 理解情況:C程序使用C printf函數進行輸出。Java的printf方法緊跟在C printf函數之後,所以C輸出語句可以非常容易地轉換成Java。。

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

這周明顯感覺難度上去了,剛開始敲書上的代碼時先敲得前面的發現不能運行,後來發現要先敲後面的再敲前面的_(:з」∠)_做後面的作業也不像之前那麽容易了,但是感覺會用java做的事情越來越多了也是一種成就感。

學習進度條

代碼行數(新增/累積) 博客量(新增/累積) 學習時間(新增/累積) 重要成長
目標 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
  • 計劃學習時間:20小時

  • 實際學習時間:24小時

  • 改進情況:本周學習內容多,所以學習時間有所加長

參考資料

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

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

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