9/25/2011

BCS2233 OOP Contoh Test 1



Chapter : 1 to 5
Date : 4/10/2011
Time : 8:30 am (L22)
[ OPEN BOOK (only Liang's slide / book) ]





1. What is debugging? [3 marks]

2. What is the difference between a constant and a variable? [3 marks]

3. What is Overloading Methods? [3 marks]

4. Which of the following are invalid identifiers, why? [8 marks]

a) one
b) hello
c) my Window
d) JAVA
e) 1234
f) hello,there
g) acct122
h) DecafeLattePlease


5. Evaluate the following expressions: [4 marks]

a) 3 + 5 / 7
b) 3 * 3 + 3 % 2
c) 3 + 2 / 5 + -2 * 4
d) 2 * (1 + -(3/4) / 2) * (2 - 6 % 3)


6. Evaluate the following boolean expressions. Assume x, y, and z have some numerical values.
[3 marks]

a) 4 < 5 || 6 == 6
b) 2 < 4 && (false || 5 <= 4)
c) !(z != z)

7. Write a while statement to add numbers 11 through 20. [5 marks]

8. Write a while statement to continuously read in real numbers and stop when a negative number is entered. [5 marks]

9. For each of the following loop statements, determine the value of sum after the loop is executed. [6 marks]

a. int count = 0, sum = 0;
while ( count < 10 ) {
sum += count;
count++;
}


b. int count = 1, sum = 0;
while ( count <= 30 ) {
sum += count;
count += 3;
}


c. int count = 0, sum = 0;
while ( count < 20 ) {
sum += 3*count;
count += 2;
}

10. Write a do–while loop to compute the sum of the first 30 positive odd integers. [5 marks]

11. Write a for loop to compute. [9 marks]

a. the sum of 1, 2, . . . , 100.
b. the sum of 2, 4, . . . , 500.
c. the product of 5, 10, . . . , 50.


12. Write method headers for the following methods: [6 marks]
a. Computing a CPA, given the Number of Credit and the Total Points.
b. Printing the calendar for a year, given the year.
c. Computing a square root.
d. Testing whether a number is odd, and returning true if it is.
e. Printing a message a specified number of times.
f. Computing the monthly payment, given the loan amount, number of years, and annual interest rate.




No comments:

Cara download Installer windows 10 dalam format ISO

1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan.  ...