EECS2030E Practice Test 1A

PRACTICE

This is a practice test. The actual test may contain fewer or more questions. The actual test may or may not supply you with other materials (such as starter code).

The Java API is here.


Question 1

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


Question 2

Create a text file named answers.txt (use File->New-> Untitled text file in eclipse). Type your answer to the following question in the text file.

A.

Consider the field Practice1A.TEST_VERSION. What does the keyword final mean when used to modify a field?

B.

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

    List<Character> aList = Arrays.asList('g', 'o', 'o', 'd', 'b', 'y', 'e');
    Practice1A.shuffle(aList);
    

The first line of code creates the list ['g', 'o', 'o', 'd', 'b', 'y', 'e'], and the second line of code calls the shuffle method from Question 1.

The memory diagram illustrating the state of memory for the two lines of code is shown below. What suitable values of a, b, and c would complete the memory diagram?

           ---------------------
           |    main method    |
           ---------------------
    aList  |        a?         |
           ---------------------
           |                   |
           |                   |
           ---------------------
       b?  |    List object    |
           ---------------------
           |                   |
           |                   |
           ---------------------
           | Practice1A.shuffle|
           ---------------------
        t  |         c?        |
           ---------------------
    
C.

Consider the method Practice1A.hello(String) from Question 1. What precondition does the method have? Suppose that as the implementer, you wanted to remove the precondition from Practice1A.hello(String); how could you change your implementation to remove the precondition?

D.

Provide 3 test cases for the method Practice1A.toString(List<Character>). Make sure that each test case tests a different feature of the method (i.e., don't provide 3 test cases that all check if the correct string was returned). For each test case, provide a one sentence explanation of what the test case is testing.