2009年6月23日 星期二

真心告白

這學期學的東西說多不多,不過還是讓我有點喘不過氣,原因就是自己大一不長進,上計概上機課時沒有好好學習到寫程式的精要跟重點。學習程式用背的根本就沒辦法讓自己進步,不過老師上的JAVA倒是很讓人可以融入學習的步調,尤其是每個Lab互相都有相關聯,比較不會讓人摸不着頭緒。前面寫過的Class,後面的Lab還是可以拿出來用。我想這種引導式教學是相當好的,尤其是老師上課也不會單調,不會一直講程式怎麼寫,而是連JAVA的一些歷史背景也有介紹,聽這些東西蠻有意思的,上起課也不會無聊。

這學期上課也讓我感觸良多,尤其是看到資工的兩個學長每次總是最早交出Lab,有時想程式怎麼寫,覺得卡卡的時候就會觀摩他們的Lab,這時就會覺得他們的思維真的是有經過訓練,邏輯能力真的是吾所不及,雖然這是人家的本行,不過還是會覺得我們電子系學生普遍程式能力不足,讓我想到老師說的:現在的世界是買硬體送軟體,以後是買軟體送硬體。系上對於程式相關課程應該要更重視一點!

最後,謝謝老師對於身心障礙者的用心,親人有身心障礙者就會知道對待身心障礙者是需要花很多苦心的,或許對老師可能不算什麼吧,不過還是值得我給老師喝采!

2009年6月17日 星期三

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.


2009年6月15日 星期一

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)

2009年6月1日 星期一

Lab Modular Sorting

Write a sort method which takes a double array as parameter
and returns the sorted array. Call this method in a main program.

Hint: The lab is a rewriting of Lab Sorting
to make the sorting procedure a reusable method.




Lab Array

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

2009年5月26日 星期二

Lab: Static Method II

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




將4/28的LAB稍作修改便能得出

2009年5月25日 星期一

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.



2009年5月11日 星期一

Lab Static Method

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

Lab Math methods

Compute the following mathematical functions.

Math.round(3.2)
Math.round(3.6)
Math.floor(3.2)
Math.floor(3.6)
Math.ceil(3.2)
Math.ceil(3.6)

Lab Finding the max of three numbers

Write a static method that computes the maximum of three float numbers.

Homework 5-4-2009

Do Project 7 of Chapter 4.




2009年5月4日 星期一

Lab Java Constructor

Write constructors in the lab Fraction Addition.


Lab Method Overloading

依據Class definition 3,修改程式使其接受三種setDate

date1.setDate(1,2,2008);
date2.setDate("February",2, 2008);
date3.setDate(2008);


Homework 4-27-2009

Do project 2 of Chapter 4.

強烈要求同學一定要親自動手做,鼓勵同學將理論與實作密切配合。
相信只要同學真正的努力用功,縱使資質稍差,應該都可以學到Java程式設計之知識

2009年4月27日 星期一

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.


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?


2009年4月26日 星期日

Homework 4-13-2009 Fraction Multiplication

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

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



2009年4月13日 星期一

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



2009年3月30日 星期一

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?



因為宣告month時是用private來宣告,只可以在DateFirstTry這個class使用

lab class definition

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




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



2009年3月29日 星期日

Homework: 3/23/2009

Write a program to calculate average income by gender based on the following data, where F stands for female and M for male.

F 62,000
M 25,000
F 38,000
F 43,000
M 65,000
M 120,000
F 80,000
M 30,100

You should be able to allow users to type in a whole line such as F 80,000 followed by next line M 30,100.

Lab Cosine

Write a Java program to calculate the triangular function as follows:
Cos(x)=1 - x 2 /2!+ x 4/4!- x 6/ 6!...

2009年3月23日 星期一

Lab Fibonacci

List the first 100 numbers and the ratio of
a number to its previous number, such as 1/1 = 1, 2/1 = 2, 3/2 = 1·5, 5/3 = 1·666..., 8/5 = 1·6, 13/8 = 1·625, 21/13 = 1·61538....

Want to know more about Fibonacci number



結果趨近黃金比例1.618

Homework 3-16-2009

1. Project 7 of Chap. 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

2009年3月17日 星期二

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.

2009年3月16日 星期一

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.

2009年3月15日 星期日

Homework 3-9-2009

1. Do Project 4 in Chapter 2

2. Do Project 5 in Chapter 2

3. Do Project 6, in Chapter 2

4. Do Project 7, in Chapter 2