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

1. (15 points; 3 points each) Multiple choice: circle the best response to each.

ID: 670035 • Letter: 1

Question

1. (15 points; 3 points each) Multiple choice: circle the best response to each.

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

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

1.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)

1.4. Suppose you want to set the double variable oneToThree to a random real number uniformly distributed in the interval [1.0, 3.0). You have made the following declaration: Random r = new Random1L(); noting that r.nextDouble() returns a random real number uniformly distributed in the interval [0.0, 1.0). Which statement will set oneToThree to the desired result?

A. * r.nextDouble();

B. + 2.0 * r.nextDouble();

C. + r.nextDouble() + r.nextDouble();

D. + r.nextDouble() + r.nextDouble();

1.5. Suppose you want to display the image file brutus.jpg in a browser, along with other content as organized in the HTML file index.html. Both these files are in the same folder/directory. Which HTML code fragment in index.html will produce the desired result? (Note that a well-formed HTML document such as the one you were to create for project #1 is an XML document.)

brutus.jpg

D.

Explanation / Answer

1.1

Explanation:


In design-by-contract, the client code is responsible to pre check the condition before calls the method.

Hence, the correct option is A.
A. the client code that calls the method.

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

1.2

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 .

Hence, the correct option is C.
C. formal argument.

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

1.3

Explanation:


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

Hence, the correct option is D.
D. assign an exam score of 42 to student k

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

1.4

Explanation:

Formula: minimum range + (maximum range – minimum range) * r.nextDouble ();

Hence, the correct option is B.
B. + 2.0 * r.nextDouble ();

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

1.5

Explanation:

In HTML, <img> tag is used to display an image in the webpage, and src (Source resource code) is an attribute of <img> tag.

Hence, the correct option is B.
B. <img. src="brutus.jpg"/>