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.

lab recursive method

Write a recursive method to compute Fibonacci series.

Hint:

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

2008年1月10日 星期四

期末報告題目

第一本書:Java物件導向與資料結構 (詹鎮熊 譯)

出版社:碁峰資訊股份有限公司

出版日期:2002年11月初版

Chapter 2:物件( p60頁,習題第6題)

題目:依據下列字串
String str = "123456789";

對下面的每個問題用一行程式碼回答。
a.將"ABC"插入到原始字串的4與5之間以產生一個新字串。
b.將 a 裡面新產生的字串索引值2到6(不包含6)之間的所有字元取出以形成一個新字串。


對字串還不太熟悉,有些東西還是沒辦法很快的做出來,想藉由這題讓自己熟悉字串的語法。
藉由一個程式的執行,改變原來的字串,得到一個新的字串。


第二本書:Java 2物件導向程式語言(位元文化 編著)

出版社:文魁資訊股份有限公司

出版日期:2005年6月初版1刷

Chapter 6:陣列的宣告(p6-34 習題第11題)

題目:請完成以下兩陣列的相乘計算。


最近剛學陣列,趁印象還比較深刻的時候,趕緊找一些題目來練習,以增加自己的印象。
這程式讓我學習到如何宣告一個多維的陣列,進而延伸到兩個多維陣列的運算。


第三本書:Java程式設計(Douglas Bell˙Mike Parr著 陳清木 審閱 柳望君 譯)

出版社:台灣培生教育出版股份有限公司

出版日期:2007年7月

Chapter 3:使用繪圖方法(p3-16 習題第3.7題)

題目:設計同心圓箭靶,並加入不同色彩。

我們修這門課叫Java物件導向,當我在書上看到有關於訊息方塊的程式,
就覺得這東西比較像物件,所以就嘗試想要寫一個這樣的程式。
這程式讓我學習到如何宣告一個訊息方塊,進而在方塊上加上按鈕等物件,
還學習如何畫圓並在圖上上色,讓我第一次做出彩色的Java。

2008年1月5日 星期六

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月4日 星期五

Lab Array

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

2007年12月28日 星期五

Lab: Static Method II

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



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.



2007年12月27日 星期四

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


2007年12月21日 星期五

Lab Java Constructor

Use Display 4.14 to call 4.13 (2nd ed.) orDisplay 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);



2007年12月12日 星期三

Homework 12-7-2007

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

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);


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 of2 fractions should be equal to a fraction.Use 1/2+1/3 as the test.
Hints:
Fraction f1, f2;
f1.add(f2);


Homework 11-30-2007










2007年11月30日 星期五

Lab counter

Define a class called Counter whose objects count things. An object of this class records a count that is a nonnegative integer. Include methods to set the counter to 0, to increase the count by 1, and to decrease the count by 1. Include an accessor method that returns the current count value and a method that outputs the count to the screen. Write a program to test


Class Definition 3

Do Display 4.7 (3rd, 2nd ed.) or 4.5 (1st ed.). Then use Display 4.8 to call 4.7.
Question
In Display 4.7, if the method setDate has the parameter as setDate(int month, int day, int year), what kind of changes should be made in its body of codes?










Homework 11/16/2007: lab class definition 2

1. Comment out date.setDate(6, 17, year); by // date.setDate(6, 17, year);





2. At the next line below, add date.readInput();
3. Run the program again. Fix any problems you may encouter along the way



4. At the last line of your program, add System.out.println(date.month);



and see what happens. Why?
由於前面的類別宣告為private的關係,private具有保密的作用,
而不讓user任意查看資料內容,所以程式才會發生錯誤,如果將
private改成public,則就能印出date.month的內容囉!!













2007年11月16日 星期五