Chapter 6.1~6.5

November 28, 2007 at 3:39 pm (Uncategorized)

6.1 1. (true true false true) (false true false true) (true false false true)2. Fill in the truth values in the following truth table:a.true b. false c.trued.false4. !> &&> //5. If ( min <= x && x<=max)System.out.println( “X is between the millennium and the maximum)6.2 1. a.If number greater than 0 that we do the work on action 1; if number smaller than 0 then we do the work on action 2. b. If number between 0 and 100, then we do the work on action 1; if number smaller than 0 and greater than 100, then we do the work on action 1. 2. That every line in a program is executed at least once. And this is not the same thing as testing all possible logical paths through a program, which would provide a more thorough test, but also might require considerably more test data. 3. They are equivalent from the perspective of testing the same paths through the program. For example if the employee type is 1, test data for he payroll program fall into just two equivalence classes: hours between 0 and 40 and hours greater than 4. It is near the boundaries between equivalence classes. And it si common for programs to fail at these points. For example, for the payroll program, this requirement means testing with hours equal to 39, 40 and 41. 5. It is with data at the limits of validity. For example, we choose hours worked equal to 0 and 168 hours. 6.6.31. A:the time is before noon B: the day is monday So A true and B true, than they will take the computer science quiz. And A true B false, than they will go to gym class. A false B true, than they will go to gym class. A false B false, than they will take the computer science quiz.2. What is the difference between a nested if statement and a multiway if statement ?Nested if statement provide one mechanism for dealing the complexity, and it offer an alternative. But Multiway statement is compared to the two-way and one-way if statements we have seen earlier.6 .41. Income need to change, which like: income > 20000 change to income > 20000 && income 50000.2. if (income > 10000)rate = 0.10;else if (income > 20000 && income 50000)rate = 0.40;elserate = 0.06.51.a)output will be 2, 3, run for three  times which 2,3 2, 3 2, 3 b.)out put will be 1,2,3 1, , 31, 2, 3 run for three times6.61.a) To test the number, we must test number that is bigger than 0, for example 1, 2,3. But it the number is smaller than 0, the test is wrong.b). Test the number that is bigger than 0 and smaller than 100, example, 1, 2, 3, 99, 98, 97. The number that is bigger than 100 or smaller than 0 will no be test number.2.3. When a loop that does not executes a fixed number of times, tis test data should be cover all tree possibilities. 4. A program that tolerates errors in user inputs and recovers gracefully is robust program.

Permalink Leave a Comment

5.4 The Structure and Behavior of Methods

November 5, 2007 at 1:46 pm (Uncategorized)

1. Explain the difference between formal parameters and actual parameters.
The formal parameters are parameters listed in a method’s definition, and the actual parameters are values passed to a method wen it is invoked.

2. How does Java transmit data by means of parameters?
When a method is called, the value of the actual parameter is automatically transfered to the corresponding formal parameter immediately before the method is activated.

3. Define a method sum. This method expects two integers as parameters and returns the sum of the numbers ranging from the first integer to the second one.
public the Sum(){
int sum;
sum = (int) Math.round (a + b);
debug(”Sum; “average);
retirn sum;
4. What is the purpose of local variables?
It is convenient to have temporary working storage for data in a method.

Permalink Leave a Comment

Chapter 5.

November 1, 2007 at 3:25 pm (Uncategorized)

1. an object is a runtime entitty that contains data and responds to message.
a class is a software package or template that describes the characteristics of similar object

2. -The object will then be delected from the memory storage.

3. first, an object has behavior as defined by the method of its class.
second, an object has sttate, which is another way of saying that at any particular moment its
instance variables have particular value.
Third , an object has its own unque identity, which distinguishes it from all other objects in the
computer’s memory ,even those that might momentarily have the same state.

4.The client and server are the two objects that involved when messages are sent. The relationship between them are a client’s interactions with a server are limited to sending a message.

5 The class’s interface remains the same thing as the class’s implementation details, both of them can be changed radically without affecting any of its clients.

X 5-2
1. Messages that change an object’s state are called mutators. The accessors is another messages to access the object’s state if the mutators worked correctly.
2.Private and public are visibility modifiers.Both privated and public are ommited, the consequences vary with the circumstances. Omitting the visibility modifier is equivalent to using public. use privae for insance variables unless there is some compelling reason to declare them public.

3. A constructormethods is one or more methods that indicate how to initialize a new object.

4. It can returns a string containing the student’s name and test scores.

5.We can set two variables equal to each other. For example, i am talking about student 1 for my one of variables, and now i am going to need another student for my vaiable. So i set S1(student 1)=S2(student 2). When we set something equal something in java system, the domonstrate that these two variables are refer to the same object.

6. The different between the primitive types and the reference types are in memory. The primitive type’s variable is best viewed as a box that contains a value of that primitive type. A variable of a reference type is thought of as a box that contains a pointer to an object.
The example for the primitive type is (int, double).
The example for the reference type is (allclasses, for instance).

7.It mean the statement is no longer references anything

8.When a program attempts to run a method with an object that is null. For example,Let String str=null;
And System.out.println (str.length());

9. Default Constructors is what we have been so far have had empty parameter lists, this constructor initializes numeric variables to zero and object variables to null, thus indicating that the object variables currently reference no objects.

10. The Java will let all the numeric value become zero, and all null value.

11.The purpose of a constructor is to initialize the instance variables of newly instantiated object.

Permalink Leave a Comment