星期一, 4月 28, 2008

No classes on May 5 and May 12

I am presenting 2 papers at IEEE ISWPC, Santorini, Greece. Therefore, there will be no class on May 5 & May 12.

Conference dates: May 7~9, 2008

Trip to WWW2008, Beijing, Apr 20~Apr 26

Link to YJ Chang's blog

Homework 4-28-2008

lab counter

lab class definition 3

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

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?

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?

星期一, 4月 14, 2008

4-21-2004 不上課

Due to the midterm week, we will not meet on Apr. 21. Wish you good luck!

ps. 4-21-2008 沒有 homework.

Partial Answer to Quiz 2

Partial solutions: The following solutions are not complete Java programs. They are kept brief to illustrate the main ideas of the complete programs.

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;

}

lab class definition

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

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

Quiz 2: 4-14-2008

Format: closed book
Running time: 30 min.
Scope: Chap. 3

Average income by gender

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.

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

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 Fibonacci numbers

Do Project 3.3 (1st ed.) or Project 6 (2nd ed. & 3rd ed.) 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