Archive for October, 2007

Chapter 5, 5.1

1. What is the difference between a class and an object?
-A class is a collection of methods and an object is when the method is used, meaning a method with the signiture.

2. What happens to an object’s memory storage when it is no longer referenced by a variable?
-The object will then be delected from the memory storage.

3. List the three important characteristics of an object.
-Behavior, state, and identity.

4. Describe the client-server relationship.
-The client and server are the two sides of message processing, and respectively, they are sender and receiver. They have limited knowledge of the other. In fact, client have little knowledge of how the server works internally. Only the programmer of the class need to know the internal operation. All client need to know are the methods of that class. They interact with each other via interface. A change in one doesn’t affect the other a lot.

5. What is the interface of a class?
-This is the place where client interact with the server. It’s a list of the methods supported by the server.

chapter 4, 4.9

1. Describe the logic errors in the following loops:
a. the < sign shoud be<= since it is inclusive.

b. It should be <= 10 instead of != 10, or it will go forever.

Chapter 4, 4.8

1. Describe in English what the followying code segment does:
-It means to open a scanner on the file desired to be used. Then the date in the file will be output into to the program that is being written.

Chapter 4, 4.7

1. Describe in English what the followying code segments do:
a. It means that the system will print all the numbers which are multiples of 2, starts from 1 till the limit of i.
b. The random generator generates a random number between 0 and 10, then it lets player to guess a number. The while loop run until the player guess the right number, or it will keep running.

2. Write code segments that use loops to perform the following tasks:
a. int x=1,y,z;
while(x<20){
if(x%2 !=0){
y =x*x
z =x*x*x
System.out.println(y + ” ” + z);
}
x++
}

b. int x;
while(x<20){
if(x%2==0){
System.out.print(x)
}
}

Chapter 4, 4.3

1. Why does Jill use a while statement in her instructions to Jack?
-Because he wants Jack to do the job as long as there are any cows left in the west paddock, as long as the condition holds true.

2. Why does Jill use an if-else satement in her instructions to Jack? Write pseudocode control statements that are similar in style to the farm example for the following situations:
-Jill uses the if else statement in order to have Jack do one job in a given condition and another job in a different given condition.
a. If a checker piece is red, then put it on a red square; oherwise, put it on a black square.
– if (checker piece is red) {
put it on a red square;
}else{
put it on a black square;
}
b. If your shoes are muddy, then take them off and leave them outside the door.
-if(your shoes are muddy){
take them off and leave them outside the door;
}
c. Pick up all the marbles on the floor and put them into a bag.
– if(marbles on the floor){
pick them up and put them into a bag;
}

3. Describe in English what the following code segments do:
a. If x is greather than y, x’s value is assigned to temp, then y’s value is assigned to x, at last, temp’s value, which is the value of x, is assigned to y. So the original values of x and y exchange. If x is smaller than y, then inverse process happen, and the value of x and y exchange.

b. While count’s value is less than the assigned value of total, there is a value assigned to x, and sum is then assigned the value of its original value plus the absolute value of x’s assigned value, also, count’s value becomes its original value plus one. Then if the total is greater than o, program will print the value of sum’s value divided by the total’s value.