EECS2030E Test 4

Version A

You have 80 minutes to complete this test. This is a closed book test.


GETTING STARTED

  1. Start eclipse.
  2. Download this project file.
  3. Import the test project by doing the following:
    1. Under the File menu choose Import...
    2. Under General choose Existing Projects into Workspace and press Next
    3. Click the Select archive file radio button, and click the Browse... button.
    4. Navigate to your home directory (the file chooser is probably in the workspace directory).
    5. Select the file test4A.zip and click OK
    6. Click Finish.
  4. All of the files you need for this test should now appear in eclipse.
  5. Open a terminal. You will use this terminal to submit your work.
  6. Copy and paste the command cd workspace/Test4A/src/test4 into the terminal and press enter.

Resources


Question 1 (18 marks total)

Implement the class described by this API. You do not have to include javadoc comments.

submit 2030L secEtest4A Test4A.java


Question 2 (12 marks total)

Consider the following method:

    /**
    * Returns true if n contains an even number of digits and false otherwise.
    * 
    * @param num
    *            an integer
    * @return true if n contains an even number of digits and false otherwise
    */
    public static boolean evenNumberOfDigits(int num) {
        if (num < 10) {
            return false;
        }
        return !evenNumberOfDigits(num / 10);
    }
A. (1 marks)

What precondition is required to ensure that the base case is correct as it is currently written?


B. (1 marks)

Suppose that the correct precondition from Part A is added to the method. Explain why the base case is correct.


C. (3 marks)

What should we assume about the recursive call evenNumberOfDigits(num / 10) if we wanted to prove that the recursive case is correct?


D. (2 marks)

Using your assumption from Part C prove that the recursive case is correct.


E. (2 marks)

Define the size of the problem solved by evenNumberOfDigits(num).


F. (2 marks)

Using your definition from Part E prove that the method terminates.


G. (1 marks)

What is the big-O complexity of the method? No proof is required.


submit 2030L secEtest4A answers.txt