EECS2030E Test 1

Version D

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


GETTING STARTED

  1. Start eclipse; this will take a couple of minutes because eclipse is being run for the first time using your test account.
  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. You may have to wait about 10 seconds before the file browser appears.
    4. In the file browser that appears, navigate to your home directory.
    5. Select the file test1D.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/Test1D/src/test1 into the terminal and press enter.

Resources


Question 1 (18 marks total)

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

To submit your programming question:

submit 2030L secEtest1D IntUtil.java

Question 2 (12 marks total)

A. 2 marks

What is the definition of the term "method postcondition"?

 

B. 3 marks

Consider the following (incomplete) implementation of isPeriodic(List<Integer> values, int n) from Question 1:

public static boolean isPeriodic(List<Integer> values, int n) {
    String result = false;

    /* rest of implementation not shown here */

    return result;
}

Suppose a client writes a main method that includes the following three lines of Java code:

List<Integer> numbers = Arrays.asList(1, 2, 3, 1, 2, 3);  // the list [1, 2, 3, 1, 2, 3]
int repeats = 3;
boolean ans = IntUtil.isPeriodic(numbers, period);

The memory diagram illustrating the state of memory at the moment that the method is about to return its result back to the client is shown below. What suitable values of a, b, and c would complete the memory diagram?

             ---------------------
             |    main method    |
             ---------------------
numbers   100|         a?        |
repeats   102|     not shown     |
ans       104|         b?        |
             ---------------------
             |                   |
             |                   |
             ---------------------
          300|    List object    |
             ---------------------
             |                   |
             ---------------------
             | isPeriodic method |
             ---------------------
values    800|        300a       |
n         802|         c?        |
result    804|     not shown     |
             ---------------------
             |                   |

 

C. 3 marks

Identify the 3 errors in the Javadoc shown below for the method areIdentical(List<Integer> values) from Question 1.

/**
 * Given a sorted list, returns true if all of the elements of the list are
 * equal (have the same value), and false otherwise. The method does
 * not modify the list.
 * 
 * @return true if all of the elements of the list are equal
 * @pre. values.size() != 0
 */
public static boolean areIdentical(List<Integer> values)

 

D. 4 marks

Consider the following (partial) implementation of the method isPeriodic(List<Integer> values, int n) from Question 1:

public static boolean isPeriodic(List<Integer> values, int n) {
    boolean result = false;
    if (values.size() > 0) {
        // Assume that there is some code here (not shown) that attempts
        // to implement the method correctly.
    }
    return result;
}
    

(a) Is there a test case that would reveal an error in the implementation shown above? If so, what is it?

(b) When writing a unit test for isPeriodic(List<Integer> values, int n), should we use the input list [1, 2, 3, 4, 1, 2, 3, 4] and n = 3? Why or why not?

 

To submit your written questions:

submit 2030L secEtest1D answers.txt