星期五, 10月 31, 2008

Homework 10-31-2008

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

Answer to Quiz

1. Write a Java program to calculate the trianular function as follows:
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

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

Quiz 10-31-2008

1. Write a Java program to calculate the trianular function as follows:
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

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


參觀老師的新蘇格蘭遊記

10-31-2008 小考

範圍: Chap 1~3
可攜帶: 課本,一張A4筆記,計算機

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.

星期五, 10月 03, 2008

Homework 10-3-2008

1. Complete Lab Keyboad processing
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

Due 10/24/2008 13:00

Lab: 增加回應功能

1. 以一段程式自動擷取部落格的回應留言,讓你的部落格產生最新回應,沒有時差。
2. 請你的同學給你一個 comment,是否能正確顯示在最新回應上。
3. 實例

Lab: Numerical Method

Project 1 of Chap. 2.

Lab Keyboad processing

Project 3 of Chap. 2.

Lab Keyboard Input

Rewrite Display 2.6 using BufferedReader.

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

Lab Scanner

Do Display 2.6.

What is ASCII?

星期三, 10月 01, 2008

Notice

10月10日Java課程,暫停壹次。(國定假日)
10月17日Java課程,暫停壹次。

I will present papers at ACM ASSETS 2008 in Halifax, Canada.