Question: Consider the following contract specification for the static method average. Please note that, both in the specification and in the Java programming language, the integer-division

 Consider the following contract specification for the static method average. Please

Consider the following contract specification for the static method average. Please note that, both in the specification and in the Java programming language, the integer-division ('/') operator's result is obtained by truncating toward zero. Hence. (-3/2) = -1 and (9/2) = 4. It is like "rounding", except that the quotient given as the result is not necessarily the closest integer to the correct rational quotient: it is the first-encountered integer closer to zero than the correct rational quotient. Returns the integer average of two given {@code int}s. @param j the first of two integers to average @param k the second of two integers to average @return the integer average of j and k @ensures average = (j+k)/2/public static int average (int j, int k) {...} Answer the following questions. Provide an argument justifying the following claim: The average (as defined here) of two Java ints i and j is representable as an int. regardless of the lower and upper bounds on the value of an int. Provide an implementation of the average method with int as the only type you use (except, perhaps, for boolean)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!