a) Write at least two good specifications for the following, /** Compute the square root of a number. @param ?? @returns
Posted: Fri Jun 10, 2022 11:55 am
a) Write at least two good specifications for the following, /** Compute the square root of a number. @param ?? @returns ?? @throws ?? if any public static int squareRoot(int x); b) Write non-trivial precondition for the multiply method (e.g. dont write b=0), so that the returned result is a*b. public int mult (int a, int b) { if (b == 0) return b; else return a + mult (a, b-1); } c) Given the following interface class (Mode) with a single method, getMode, that is subsequently implemented by the myMode class. public interface Mode { /** * Finds one of the most frequent integers in an array. * @param values array in which at least one value occurs more than once. * @return a number that appears most often in values */ public int getMode (int[] values); } Along with a class that implements it: public class MyMode implements Mode { /** * TODO */ @Override public int getMode (int[] values) { } } Using class discussion on specification write a spec for MyMode.getMode() in which the precondition and post-condition are both different from Mode.getMode(), while ensuring at the same time that MyMode is a well-defined spec that legally implements Mode. Hint: the new precondition must be weaker and the new post-condition must be stronger.