星期五, 11月 30, 2007

Homework 11-30-2007

1. Do Temperature Project, which is Project 7 (3rd, 2nd ed.) or Project 3 (1st ed.).
2. Do Lab Counter.

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?

星期五, 11月 16, 2007

Homework 11/16/2007: 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 class definition

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

態度決定高度

得知有同學回家是不看Java,也沒有課本,
只有上課時來抄襲旁人的作業,在此只好明說,這門課不是 All-Pass。
上學期有八人因為知道無法及格,於期末退掉這門課,
整學期的努力最後必須退掉並不值得鼓勵。

另外對於不少人非常認真想學好Java,尤其是過去沒有電腦程式基礎的同學,無論前兩次小考結果如何,老師都要給你們鼓勵,欣賞你們用心的態度。

祝大家期中考有好的表現,也隨時照顧好自己。

星期五, 11月 09, 2007

Makeup Work 11/9/2007

第二次小考未通過者,你可以使用JBuilder 重做全部三個題目,學期末將參酌加分。最慢繳交日期 11/25。
尤其前兩次小考都未通過者,這個加分將加在佔總分40%的平時分數裡面。

For those who didn't pass Quiz II (see the list), you are encouraged to write complete Java programs and run them on your JBuilder. Please present your source codes and the answers that your programs produce.

Your makeup work can be posted to the following comment area, as usual.

Partial Solutions to Quiz II

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:

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


Problem 2:

int evenSum=oddSum=0;

for(i=1; i<=25; i++)
{
if(i%2==0)
evenSum=evenSum+i;
else
oddSum+=i;

}

Perforamnce Alert (didn't pass either Quiz 1 or Quiz 2)

9325121
9326206
9326223
9326246
9326251
9326256
9326268
9326309
9326314
9426113
9426114
9426130
9426224
9426228
9426236
9426332
9426365
9441142
9441210
9442234

Quiz 11/9/2007: Result

PASS
9326125 (100/150)
9326227 (100/150)
9426106 (100/150)
9426147 (80/150)
9426202 (120/150)
9426212 (125/150)
9426214 (75/150)
9426352 (150/150)
9426364 (150/150)

No PASS:
9325121
9326206
9326222
9326223
9326246
9326251
9326256
9326268
9326309
9326314
9326315
9426113
9426114
9426130
9426208
9426219
9426224
9426228
9426236
9426324
9426332 (No show)
9426365
9441142
9441210
9442234
9444162

Quiz 11/9/2007

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 sin function as follows:
sin(x)=x - 3!/x 3 + 5!/x5 - 7!/x7 ...

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 25.

3. (70) Write a program to calculate average science scores by gender based on the following data, where F stands for female and M for male.

M 82
M 65
F 88
M 63
F 75
F 90
F 90
M 70

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