Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.In design-by-contract, the code responsible for making sure the precondition (

ID: 669895 • Letter: 1

Question

1.In design-by-contract, the code responsible for making sure the precondition (requires clause) is true when a method is called is: A. the client code that calls the method B. the code that implements the method C. both the client and the implementation code D. neither the client nor the implementation code

2. Consider the following method signature: private static int examScore(int studentNumber) {...} Here, studentNumber is called: A. a distinguished variable B. an argument (or actual parameter) C. a formal parameter D. an index

3. Suppose the method from question 1.2 is called in the following statement: int k = examScore(42); This call would certainly: A. be illegal in Java (i.e., it’s a compile-time error) B. cause the program to crash when it is executed (i.e., it’s a run-time error) C. print out the exam score of student #42 D. assign an exam score of 42 to student k E. be legal in Java (though flagged by CheckStyle)

Explanation / Answer

Answers:


The correct answer for question 1 is A
A)the client code that calls the method.

Explanation:
In design-by-contract, the client code is responsible to precheck the condition before calls the method.

----------------------------------------------------------------------------------------

The correct answer for question 2 is C.
C)formal argument.

Explanation:
Formal argument is used in a method to stand for the value that is passed to the method by caller.
In the method signature private static int examScore( int studentNumber),
studentNumber is the formal argument which is used to pass the studentNumber , an formal argument .

----------------------------------------------------------------------------------------

The correct answer for question 3 is D.
D)assign an exam score of 42 to student k

Explanation :
The statement int k=examScore(42); that calls the examScore with actual arguemnt
value 42. The return value is assigned to integer k.


Hope this helps you