EECS2030E Test 1

Version A

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. 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 test1A.zip and click OK
    6. Click Finish.
  3. All of the files you need for this test should now appear in eclipse.
  4. Open a terminal. You will use this terminal to submit your work.
  5. Copy and paste the command cd workspace/Test1A/src/test1 into the terminal and press enter.

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 secEtest1A DiceUtil.java

Question 2 (12 marks total)

A. 2 marks

In the declaration of a public static final constant what does the keyword static mean?

 

B. 3 marks

Consider the following class having only one method:

public class StringUtil {

    public static String repeat(String s, int n) {
        // Returns a new string made by repeating the string s
        // a total of n times.

        // implementation not shown
    }
}

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

String myString = "abc";
int m = 5;
String s = StringUtil.repeat(myString, m);

The memory diagram illustrating the state of memory at the moment that the method body starts to run is shown below. What suitable values of a, b, and c would complete the memory diagram?

             ---------------------
             |    main method    |
             ---------------------
myString  100|       400a        |
       m  102|     not shown     |
       s  104|     not shown     |
             ---------------------
             |                   |
             |                   |
             ---------------------
          a? |   String object   |
             ---------------------
             |                   |
             |                   |
             ---------------------
             |  repeat method    |
             ---------------------
       s  800|         b?        |
       n  802|         c?        |
             ---------------------

 

C. 3 marks

Complete the Javadoc necessary to exactly reproduce the API documentation for the method median(List<Integer> dice) from Question 2. (NOTE: the <pre> tags are html markup, not Javadoc tags; you can ignore them for the purposes of this question.)

/**
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * <pre>
 * dice                 returns
 * ----------------------------
 * [2, 2, 3]               2
 * [3, 4, 5, 5]            4
 * [1, 2, 3, 4, 4]         3
 * [1, 1, 4, 5, 5, 6]      4
 * </pre>
 * 
 * 
 * 
 * 
 */
public static int median(List<Integer> dice)

 

D. 4 marks

Consider the following test cases for the method median(List<Integer> dice) from Question 2:

Input list        Expected result
[1, 2, 3, 4] 2
[1, 2, 3, 4, 5] 3

At least two important test cases are missing. Provide the missing test cases and explain with one sentence for each case why they are important.

 

To submit your written questions:

submit 2030L secEtest1A answers.txt