2009年1月4日 星期日

我有話要說

這學期很高興能修到老師這們JAVA,也是我這學期最認真上的一門課吧。
一直以來我對寫程式都有很高的興趣,寫過 C C++ C# 如今又多會了個JAVA。
之前寫C++和C#時,雖然知道兩者都是屬於物件導向式語言,但其實對於物件導向的概念還是很模糊,直到這學期老師上JAVA詳細解釋其之間的關係時,我才能更加體會,這讓我在在閱讀有關程式相關書籍或使用MSDN資料庫時能更加了解,對我這學期的專題有很大的助益。
其實這學期是我第一次上有關物件導向的課程,所以在上課之前就有去圖書館借相關書籍來研讀,所以整學期的課程,我都還算應付的來,課堂上的作業我也一定都在課堂上完成,一次都沒有缺交,雖然考試可能偶有疏失,但整學期下來,我真的學的很充實,唯一讓我覺得比較困難的大概只有倒數第而堂課的遞迴吧!!畢竟他的想法比較不直觀,可能需多寫後,才會上手。

也許有多人會覺得,寫程式很不好上手,很難想。
其實我覺得只要多加練習,就可以克服,而且如果你能把自己寫好的程式,一行一行有條有序,有邏輯的解釋給別人聽,讓別人聽的懂你的想法與邏輯時,你自己就能更加了解自己所寫的程式,這樣寫下來更能融會貫通。
這是我這學期所學下來的小小心得,與大家分享!!謝謝。

2008年12月22日 星期一

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 Factorial

Write a Java program that computes N! where N is a positive integer.

Hint:

public static long factorial(int n)


Lab Recursive Method

Write a recursive method to compute Fibonacci series.

Hint:

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

2.
public static long fib(int n)


2008年12月12日 星期五

Lab Static Method

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




2008年11月28日 星期五

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



Lab Overloading

Do Display 4.11



Lab ADT

Define a Complex class and write an object oriented program to compute (2+3i)+(4+5i) in Java.
The methods should include an access and a mutator.



2008年11月21日 星期五

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 of
2 fractions should be equal to a fraction.
Use 1/2+1/3 as the test.

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



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?




2008年11月7日 星期五

lab class definition 2

Study Display 4.4 (2nd ed. and 3rd ed.) or Display 4.2 & Display 4.3 (1st ed.) and then
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?



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

counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();



Homework 10-31-2008

Study Display 4.1 and then do Self-Test Exercise 1.


2008年10月25日 星期六

Homework 10-24-2008

1. Write a program to generate the series 1, 1, 2, 3, 5, 8, 13, ...
The series has a property that the third number is the sum of the first and second numbers. For example, 2=1+1, 3=1+2, and 5=2+3.



2. Write a program to generate the following table of arithmetic expressions

1*1=1 1*2=2 1*3=3 ... 1*9=9
2*1=2 2*2=4 2*3=6 ... 2*9=19
...
9*1=9 9*2=18 9*3=27 ... 9*9=81

2008年10月24日 星期五

Lab Finding the max of a list of numbers

Based on your study of Display 3.8, write a code to find the max and min of a list of number.
For example, given 1,3,5, and9, the max is 9 and the min is 1.
Your program should be able to process a list of any length.

Lab Finding the max of three numbers

Write a program to decide the max number of the three input number.

Lab: Tax Calculation

Study Display 3.1. Based on the income tax rate in Taiwan,
calculate the income tax of a person whose annual income is 1,000,000 or 2,000,000.

1,000,000


2,000,000

2008年10月23日 星期四

Homework 10-3-2008

3. Do Project 4 in Chapter 2

4. Do Project 5 in Chapter 2

5. Do Project 6, in Chapter 2

6. Do Project 7, in Chapter 2

2008年10月3日 星期五

Lab: Numerical Method

Project 1 of Chap. 2.