星期四, 12月 25, 2008
Quiz 12-26-2008
2. Design a static method that can compute the addition of fractions. You must first define Fraction class then write a demo program to verify the class program.
3. 列舉至少三個Java程式的風格
4. 列舉至少三個Java記憶體管理的特性
5. Write a Java program to solve the Hanoi Tower Problem.
6. Write a Java program to solve the Hanoi Tower Problem.
7. Explain ADT (Abstract Data Type).
8. Explain API (Application Programming Interface).
9. Write a Java program to calculate the sin function as follows:
sin(x)=x - x 3/3! + x5/5! - x7/7! ...
10. Write a Java program to calculate the cosine function as follows:
Cos(x)=1 - x 2 /2!+ x 4/4!- x 6/6!...
11. 一個Java 物件使用多少個Byte記憶體? 為什麼?
12. 請解釋 Garbage Collector 的作用。試舉例說明。
13. 請解釋 Overloading ,舉例說明何時可能會用到 Overloading
14. 請解釋 Constructor ,舉例說明何時可能會用到 Constructor
星期五, 12月 19, 2008
Lab Hanoi Tower
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
Hint:
public static long factorial(int n)
Lab Recursive Method
Hint:
1.
fib(n)=fib(n-1)+fib(n-2)
2.
public static long fib(int n)
星期四, 12月 18, 2008
星期五, 12月 12, 2008
Lab Static Method
Lab Java Constructor
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);
星期六, 11月 29, 2008
星期五, 11月 28, 2008
星期四, 11月 27, 2008
行動科技輔具冬令營 報名
Lab ADT
The methods should include an access and a mutator.
星期二, 11月 25, 2008
星期五, 11月 21, 2008
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
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
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?
星期三, 11月 19, 2008
星期一, 11月 17, 2008
星期五, 10月 31, 2008
Answer to Quiz
Cos(x)=1 - 2!/x 2 + 4!/x 4- 6!/x 6...
double power=1, fact=1, sum=0;
int k=-1;
for(int i=1; i<10; i++)
{
power=power*x;
fact=fact*i;
if(i%2==1)
{ k=k*(-1);
sum+=k*power/fact;
}
}
6. Write a complete Java program that uses a for loop to compute the sum of odd numbers between 1 and 25.
int evenSum=oddSum=0;
for(i=1; i<=25; i++)
{
if(i%2!=0)
oddSum+=i;
}
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?
lab counter
counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();
Quiz 10-31-2008
Cos(x)=1 - 2!/x 2 + 4!/x 4- 6!/x 6...
2. Write a Java program to calculate the sin function as follows:
sin(x)=x - 3!/x 3 + 5!/x5 - 7!/x7 ...
3. Write a Java program that can determine the minimum of any 4 numbers.
4. Write a Java program that can determine the maximum of any 4 numbers.
5. Let i, j be two integers. Write a Java program to exchange their values. Please make sure you have good styles of making comments, naming variables, and indenting.
6. Write a complete Java program that uses a for loop to compute the sum of the odd numbers between 1 and 25.
7. Explain syntax errors and sematic errors.
8. Explain programming styles and naming conventions in Java.
9. What is Java Virtual Machine and Java Bytecode?
10. Explain Java's feature "Write once, run anywhere."
星期五, 10月 24, 2008
Homework 10-24-2008
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
Lab Finding the max of a list of numbers
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
Lab: Tax Calculation
calculate the income tax of a person whose annual income is 1,000,000 or 2,000,000.
星期五, 10月 03, 2008
Homework 10-3-2008
Lab Keyboard Input
You need to import the following packages in the first place.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
Change
Scanner keyboard= new Scanner(System.in);
into
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
Note the Main method needs IOException handling as follows:
public static void main (String[] args) throws IOException
星期三, 10月 01, 2008
星期五, 9月 26, 2008
Homework 9-26-2008
2. Write a program that can reverse the order of an input string. For example, if you input "ab", it will output "ba". If you input "abcdefg", it should return "gfedcba".
Lab: String Processing
Write a program that starts with a line of text and then outputs that line of text with the first occurrence of "hate" changed to "love". For example, a possible sample output might be
The line of text to be changed is:
I hate you.
I have rephrased that line to read:
I love you.
Hint: You may consider use the methods: indexOf(A_String) and substring(Start, End) in your program.
Lab: Simple Arithmetics
Lab: Simple Calculation
Hint: There are 5280 feet in a mile.
星期五, 9月 19, 2008
Homework 9-19-2008
"tell me and I'll forget; show me and I may remember; involve me and I'll understand"
1. Explain bytecode, JVM
2. Explain class, object
3. Reading Assignments:
Read 1.1, 1.2, 1.3 of Textbook
4.1 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (i++);
Print i;
Ans: 2, 4, 3
4.2 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (++i);
Print i;
Ans: 2, 6, 3
4.3 Write a Java program as follows:
Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;
Ans: 3.5, 3.5
Lab 2: Java for Scientific Computation
Do Project 4 on Page 56. (2nd Edition)
Do Project 1 on Page 54. (1st Edition)
artificial sweetener 人工代糖(過量可以致癌)
diet soda pop 減肥可樂
lose weight 減肥
星期四, 9月 11, 2008
Let's start blogging
2. 張貼你的部落格的第一篇文章。一小段歡迎詞,或是簡短自我介紹,或是你最喜歡的事物與最不喜歡的事物,都可以。
3. 建立一個連結到課程網站 http://javaatcycu.blogspot.com/
建議你使用右上角"自訂"功能,新增一個區塊。一個區塊內可以置放多個連結。
4. 日後請將你的隨堂練習與作業寫在你的 blog, 然後到
Homework 或 Lab 的Comment 登錄作業blog網址就可以了.
請勿將整個作業直接寫在老師部落格的Comment處。
5. 尊重智慧財產權,引用他人文章須註明出處。並且應該合乎學術常規,以合理的方式引用。
注意事項
a. blog需正確設定時區顯示時間 。
b. 請測試他人可否留言(comment)。以方便留下回應意見。
How to insert a link at the following comment, please use the following HTML code.
星期一, 6月 16, 2008
Quiz 4 成績
9326361
9226119
9426261
9526202
9526208
9526150
9526350
9526248
9426235
9526349
中原大學電子系輔具科技夏令營 2008
邀請熱情的妳/你參加中原大學電子系輔具科技夏令營 2008,結合先端科技為弱勢服務,就從這裡開始。
報名:請在意見區寫上姓名即可。
Quiz 4
Cos(x)=1 - 2!/x 2 + 4!/x4 - 6!/x6 ...
2. Write a Java program to calculate the sin function as follows:
sin(x)=x - 3!/x 3 + 5!/x5 - 7!/x7 ...
3. Design a non-static method that can compute the product of complex numbers. You must first define Complex class then write a demo program to verify the class program.
4. Design a static method that can compute the product of complex numbers. You must first define Complex class then write a demo program to verify the class program.
5. Let i, j be two integers. Write a Java program to exchange their values. Please make sure you have good styles of making comments, naming variables, and indenting.
6. Write a complete Java program that uses a for loop to compute the sum of the even numbers between 1 and 25.
7. Explain API and ADT.
8. Explain programming styles and naming conventions
星期一, 6月 09, 2008
Lab Magic Parking Tower
Hint: You may study Display 5.14 to get some ideas.
Lab Static method
期末報告
到圖書館挑選二本Java課本,寫下這些書名與作者出版社與出版日期,每本書各挑選一個習題進行個人研究,說明以下
- 你為什麼挑選這個習題(只有題目,沒有範例或解答),
- 這個習題讓你學到什麼概念,
- 請你製作一個講義說明這個習題。
Due: 6/29/2008 at 18:00
星期五, 6月 06, 2008
星期二, 6月 03, 2008
Quiz 3
9527118
9527129
9527158
9526238
9526240
9526261
9526319
9526350
9526353
9426231
9326263
9325120
9325146
方彥順
星期一, 6月 02, 2008
Lab Java Constructor
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);
Quiz 6-2
2. Define a Complex class with complex addition.
3. What is Abstract Data Type (ADT)?
4. What is "Overloading"? Why is it useful?
5. 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.
6. 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.
星期一, 5月 26, 2008
Lab ADT, accessor, mutator
The methods should include an access and a mutator.
星期一, 5月 19, 2008
Homework 5-19-2008
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
2 fractions should be equal to a fraction.
Use 1/2+1/3 as the test.
Hints:
Fraction f1, f2;
f1.add(f2);
星期一, 4月 28, 2008
No classes on May 5 and May 12
Conference dates: May 7~9, 2008
lab counter
counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();
Class Definition 3
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?
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?
星期一, 4月 14, 2008
4-21-2004 不上課
ps. 4-21-2008 沒有 homework.
Partial Answer to Quiz 2
Problem 1:
1. Write a Java program to calculate the trianular function as follows:
Cos(x)=1 - 2!/x 2 + 4!/x4 - 6!/x6 ...
double power=1, fact=1, sum=0;
int k=-1;
for(int i=1; i<10; i++)
{
power=power*x;
fact=fact*i;
if(i%2==1)
{ k=k*(-1);
sum+=k*power/fact;
}
}
Write a complete Java program that uses a for loop to compute the sum of the even numbers and the sum of the odd numbers between 1 and 50.
int evenSum=oddSum=0;
for(i=1; i<=50; i++)
{
if(i%2==0)
evenSum=evenSum+i;
else
oddSum+=i;
}
Quiz 4-14-2008
There are 3 problem each with its own marks. Total above 75 marks is considered as PASS.
1. (50) Write a Java program to calculate the trianular function as follows:
Cos(x)=1 - 2!/x 2 + 4!/x4 - 6!/x6 ...
2. (30)
Write a complete Java program that uses a for loop to compute the sum of the even numbers and the sum of the odd numbers between 1 and 50.
3. (20) Rewrite the following for loop using a while expression.
int Sum=0;
for(i=0; i<=10; i++)
Sum=Sum+i;
星期一, 4月 07, 2008
Average income by gender
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.
Without any change made to your program, your program should be able to process a new set of data, such as follows:
M 52,000
M 35,000
F 48,000
M 33,000
F 75,000
F 110,000
F 90,000
M 30,100
Lab 9*9
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
Lab Fibonacci numbers
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
星期一, 3月 24, 2008
Homework 3-24-2008
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.
2. 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.
Lab Finding the max of three numbers
Lab: Tax Calculation
calculate the income tax of a person whose annual income is 1,000,000 or 2,000,000.
Quiz 3-24-2008
2. The identifier StreamReader is normally abbreviated as SR in programming language C. However, Java programmers normally do not use abbreviations for identifiers. What are the advantages and disadvantages of not using abbreviations?
3. a. What is "self-documenting"?
b. What is the purpose of "Unicode"? Does Java use it?
4. Give an example of "logic error"
星期一, 3月 17, 2008
Lab Keyboard input
You need to import the following packages in the first place.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
Change
Scanner keyboard= new Scanner(System.in);
into
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
Note the Main method needs IOException handling as follows:
public static void main (String[] args) throws IOException
星期一, 3月 10, 2008
Homework 3-10-2008: String Processing
Write a program that starts with a line of text and then outputs that line of text with the first occurrence of "hate" changed to "love". For example, a possible sample output might be
The line of text to be changed is:
I hate you.
I have rephrased that line to read:
I love you.
Hint: You may consider use the methods: indexOf(A_String) and substring(Start, End) in your program.
Lab: Simple Calculation
Hint: There are 5280 feet in a mile.
星期一, 3月 03, 2008
Homework 3-3-2008
"tell me and I'll forget; show me and I may remember; involve me and I'll understand"
1. Explain bytecode, JVM
2. Explain class, object
3. Reading Assignments:
Read 1.1, 1.2, 1.3 of Textbook
4.1 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (i++);
Print i;
Ans: 2, 4, 3
4.2 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (++i);
Print i;
Ans: 2, 6, 3
4.3 Write a Java program as follows:
Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;
Ans: 3.5, 3.5
Lab 2 Java for Scientific Computation
Do Project 4 on Page 56. (2nd Edition)
Do Project 1 on Page 54. (1st Edition)
artificial sweetener 人工代糖(過量可以致癌)
diet soda pop 減肥可樂
lose weight 減肥
星期一, 2月 25, 2008
Homework 2-25-2008
Due 3/3/2008 at 18:50
1. Watch The Inside Story (Video), write your words on the development and inventor of Java.
2. List at least 5 applications of Java. You must provide the references you used. We recommend Google Search engine.
ps.
Lab: Start Blogging
2. 張貼你的部落格的第一篇文章。一小段歡迎詞,或是簡短自我介紹,或是你最喜歡的事物與最不喜歡的事物,都可以。
3. 日後請將你的隨堂練習與作業寫在你的 blog, 然後到
Homework 或 Lab 的Comment 登錄作業blog網址就可以了.
請勿將整個作業直接寫在老師部落格的Comment處。
4. 尊重智慧財產權,引用他人文章須註明出處。並且應該合乎學術常規,以合理的方式引用。
注意事項
a. blog需正確設定時區顯示時間 。
b. 請測試他人可否留言(comment)。以方便留下回應意見。
How to insert a link at the following comment, please use the following HTML code.
星期二, 1月 15, 2008
星期五, 1月 11, 2008
Lab Hanoi Tower
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
Hint:
public static long factorial(int n)
lab recursive method
Hint:
fib(n)=fib(n-1)+fib(n-2)
星期二, 1月 08, 2008
星期五, 1月 04, 2008
Bonus: Modular Sorting
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.
星期四, 1月 03, 2008
星期三, 1月 02, 2008
Lab Magic Parking Tower
Hint: You may study Display 5.14 to get some ideas.