2008年1月17日 星期四

Just For Some One

今天
2008/01/18
對全人類不是個什麼大日子

出生就是煩惱

每天早上睡醒照鏡子的時候
也會有煩惱


尤其是到了考試的時候更是...
需要一些東西來解悶



但是我們不得不承認
活著很好
看看這隻貓
如此的...
安祥XD


廢話結束



胡瑋佳生日快樂啦!!!



我們站在時間軸上的同一點
我們的距離有中壢到台中這麼遠
我們的感覺
一個往右
一個往左

或許我們已經毫無關聯

但是
卻因為
就是因為
2008/01/18
就是對全人類這麼不起眼的小日子

但這個日子專屬於妳

還有妳辛苦的家人>///<

Best wish to you

By 笨蛋(看見妳的笑 我知道妳比從前快樂^ ^)

2008年1月11日 星期五

Lab Hanoi Tower

The pseudocode for Hanoi Tower is as follows:

Solve(N, Src, Aux, Dst)
if N is 0 return
Solve(N-1, Src, Dst, Aux)
Move N from Src to Dst
Solve(N-1, Aux, Src, Dst)


Write the Java program based on the pseudocode in the above.




若有n個盤子,則移動完畢所需之次數為2^n - 1,所以當盤數為64時,則所需次數為:

264- 1 = 18446744073709551615

為5.05390248594782e+16年,也就是約5000世紀,如果對這數字沒什麼概念,就假設每秒鐘搬一個盤子好了,也要約5850億年左右。

所以建議測試不要用太大數字

否則就是幾乎陷入無窮迴圈拉~

2008年1月10日 星期四

lab recursive method

Write a recursive method to compute Fibonacci series.

Hint:

fib(n)=fib(n-1)+fib(n-2)





0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...


測試第九個是否為21

2008年1月9日 星期三

期末報告

書名 JAVA資料結構與演算法
作者 廖榮貴,許正憲,王龍發,蔡能聰編著
出版 文魁資訊
出版日期 2005/4
Chap6-2
請依序輸入以下資料
23 31 34 12 93 54 66 29 83
是分別用謝爾排序法來排序
請寫出運作過程

基於我大一時候C語言到了資料結構那附近就沒交的遺憾
找了個資結與演算法
礙於時間關係
只能稍做練習




參考網址
http://caterpillar.onlyfun.net/Gossip/AlgorithmGossip/ShellSort.htm

書名 JBuilder程式設計實務
作者 楊宗誌編著
出版 文魁資訊
出版日期 2001/12
Chap4-2
某百貨公司週年慶,店內商品全面八折,試寫一程式輸入貨品單價及數量並計算其應付之金額


這本書偏於實際用途
裡面多為簡單實作併用視窗跑出
由於軟體和Turbo JBuilder有些許出入
礙於時間不足
就先用本堂課的參考書中後面有關SWING部份程式去寫






書名 JBuilder X程式設計快樂上手
作者 洪國勝,張建原編著
出版 松崗
出版日期 2004/2
Chap10-1
請寫出一個"嘻八啦"的程式,其功能如下
(1)電腦執四個骰子
(2)若有兩個數字相同就取剩下兩個的和
(3)如果沒有相同就重新骰到有相同的為止
(4)若倆倆相同,取和較大者
(5)照以上規則,寫出此程式





2008年1月4日 星期五

"Lab Magic Parking Tower"

A parking tower is out of order someday. If you park a Benz, you will end up with a Torben. Write a program to simulate this scenario. First create a class called CarParked which has a static method called outOfOrder. Name an object called yourCar, which happens to be a Benz. Your program should contain a class called CarParked and a test program called CarParkedDemo which test the method by CarParked.outOfOrder(yourCar).

Hint: You may study Display 5.14 to get some ideas.




2008年1月3日 星期四

Lab Array

Study Display 6.1, and then write a program that can sort numbers in ascending order.










  • 氣泡排序法
顧名思義,就是排序時,最大的元素會如同氣泡一樣移至右端,其利用比較相鄰元素的方法,將大的元素交換至右端,所以大的元素會不斷的往右移動,直到適當的位置為止。

基本的氣泡排序法可以利用旗標的方式稍微減少一些比較的時間,當尋訪完陣列後都沒有發生任何的交換動作,表示排序已經完成,而無需再進行之後的迴圈比較與交換動作,例如:

排序前:95 27 90 49 80 58 6 9 18 50

  1. 27 90 49 80 58 6 9 18 50 [95] 95浮出
  2. 27 49 80 58 6 9 18 50 [90 95] 90浮出
  3. 27 49 58 6 9 18 50 [80 90 95] 80浮出
  4. 27 49 6 9 18 50 [58 80 90 95] ......
  5. 27 6 9 18 49 [50 58 80 90 95] ......
  6. 6 9 18 27 [49 50 58 80 90 95] ......
  7. 6 9 18 [27 49 50 58 80 90 95] 由於接下來不會再發生交換動作,排序提早結束

在上面的例子當中,還加入了一個觀念,就是當進行至i與i+1時沒有交換的動作,表示接下來的i+2至n已經排序完畢,這也增進了氣泡排序的效率。

參考網頁
http://caterpillar.onlyfun.net/Gossip/AlgorithmGossip/SelectionInsertionBubble.htm

2007年12月27日 星期四

資料

http://caterpillar.onlyfun.net/Gossip/AlgorithmGossip/AlgorithmGossip.htm

Lab: Static Method II

Define a Complex class with a static method for computing complex addition. Use (2+3i)+(4+5i) in your test.

照樣把它改成static





有鑑於之前常常被老師糾正
不過當時還不清楚static的差異
只發現寫得出來
現在才能了解當初寫的為什麼會有兩種方式


下面呼叫的方式便可略知ㄧ二

"Lab Static Method"

Study Display 5.2.
Using static variables and static methods to implement the class Fibonacci such that
the first call to Fibonacci.next()
returns 2, the second returns 3, and then 5, and so on.

根據Fibonacci的推算
並且將method設定為static


呼叫的時候也就不用開一個新的object來做Fibonacci級數



這也解決了之前做向量以及複數的時候
內積和複數相加
表現方式不同的原因了

2007年12月20日 星期四

"Homework 12/21/2007"

Design a method that can compute the vector inner product. You must define Vector class in the first place. Write a demo program to verify your program works. You should use constructors to initialize the two vectors.

Hint: The inner product is not a vector. It is a number (scalar).

Sample answer

由於向量不同於日期
日期的月份可以用String和數字兩種形式
向量沒有這麼多的考慮
所以裡面就只有用給初值以及non-argument來看

那我們輸出這邊一組先用non-argument
一組則是有給初值
下面再把non-argument改成給初值的那個constructor

Lab Java Constructor




Use Display 4.14 to call 4.13 (2nd ed.) or
Display 4.12 to call 4.11 (1st ed.).

After you finish the above, try the following

Date birthday = new Date("Jan",1,2000);
birthday.Date("Feb",1,2000);
birthday.setDate("Feb",1,2000);
birthday=new Date("Mar",1,2000);

比較不同的就是Date()這邊的定義


Demo這邊的變化
還有constructor



另外兩個則是用正確的方法


所以就可以成功呼叫

2007年12月12日 星期三

Homework 12-7-2007 Show comments on your blog.

Show comments on your blog.

先進去老師給的網址發現
這是一位網路上的高手提供的


得到程式碼後再去修改的地方


打開來就可以發現其中有一項是我們要的



把剛剛的程式碼打上去



大功告成

Homework 12-7-2007 Complex class

Define a Complex class and write an object oriented program to compute (2+3i)+(4+5i) in Java.

Complex class


Complex Demo for (2+3i)+(4+5i)


2007年12月7日 星期五

lab Fraction equality test

Write a program to implement a method that can check whether 2 fractions are equal. You will implement a class called Fraction consisting of a numerator and a denominator. The equality test of 2 fractions should return a boolean value.

Use the following as the tests.

  • 1/2, 2/4
  • 5/6, 6/7

Hints:
Fraction f1, f2;
f1.equals(f2);


1/2 vs 2/4


5/6 vs 6/7

2007年12月6日 星期四

lab Fraction Addition

Write a program to implement a method that can do additions of 2 fractions. You will implement a class called Fraction consisting of a numerator and a denominator. The additions of
2 fractions should be equal to a fraction.
Use 1/2+1/3 as the test.

Hints:
Fraction f1, f2;
f1.add(f2);



1/2+1/3=5/6


我覺得這次的lab讓我對物件導向有更深的了解
尤其是在思考該怎麼樣用物件來思考
去寫成兩個物件相加(根據我思考的結果應該是這樣吧XD)
也突顯了我之前練習沒有去注意細節(這幾個Display都在家裡打過了= =")
雖然有挫折但是也慢慢感覺物件導向的一些威力了>///<

2007年11月30日 星期五

Homework 11-30-2007

Do Temperature Project, which is Project 7 (3rd, 2nd ed.) or Project 3 (1st ed.).


這次作業最大的問題好像是看懂題目~"~
我想題目應該是...
寫出兩個method來接收溫度
包含數字部份以及溫度的規格
所以基本就是要有接收兩組溫度的method(getData)(後面要比較)
有了兩組之後就是要有比較的method(comparison)
最後要有toString()把這些輸出
其中華氏及攝氏的轉換
數字方面只能到小數點後一位(round to nearest tenth of a degree)
接下來就是作業部分

下面是Temperature 的Class主體
由於過於龐大
先print出主體

下面這個是轉換華氏or攝氏的method


接下來是取得溫度的資料的method



輸出的method



還有比較用的method
這部分打了很多
我想也許是有太多不必要的邏輯吧







先把基本配備都弄齊全了
就可以開始RUN囉~

0C vs 32F the same



25C vs 60F 25C > 60F


25C vs 78F 25C < 78F


-40C vs -40F the same


100C vs 212F the same

這次的作業似乎比以前更為複雜
也運用了更多class跟method
也更為深入了