EECS2030Z Test 3

Version C


GETTING STARTED

  1. Start eclipse; use the workspace suggested by eclipse (or remember the directory name of your workspace).
  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.
    4. Navigate to your home directory (the file chooser is probably in the workspace directory).
    5. Select the file test3C.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/Test3C/src/test3 into the terminal and press enter.

Question 1 (30 marks total)

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

submit 2030 test3C ContactSet.java


Question 2 (20 marks total)

A. (3 marks)

Consider the following three lines of Java code:

PhoneNumber n1 = PhoneNumber.getInstance(416, 967, 1111);
PhoneNumber n2 = PhoneNumber.getInstance(416, 967, 1111);
System.out.println(n1 == n2);

The Java code shown above prints true because PhoneNumber is a particular kind of class; what name is given to such classes?


B. (3 marks)

Suppose that a client writes the following method:

public static void sort(List<Contact> contacts) {
    Collections.sort(contacts);
}

What method from the Contact class lets the client sort a list of contacts using Collections.sort?


C. (4 marks)

The API for Contact says that every contact has a name (of type String) and a phone number (of type PhoneNumber). Would you implement Contact as an aggregation or a composition of a PhoneNumber? Explain your answer.


D. (5 marks)

Consider the constructor ContactSet(ContactSet other):

(Part 1): Based on the API of the constructor, does the constructor make a deep copy or a shallow copy of the set belonging to other?

(Part 2): Your answer here depends on your answer for (Part 1); see the two choices below:

If you answered deep copy in (Part 1) then show how to make a shallow copy of the set belonging to other.

If you answered shallow copy in (Part 1) then show how to make a deep copy of the set belonging to other.


E. (5 marks)

(Part 1): What class invariant does ContactSet have regarding the contacts in its collection?

(Part 2): Based on the API for ContactSet which method allows a client to break the class invariant of ContactSet? Explain how a client can break the class invariant of ContactSet after using the method (showing actual Java code that does so is acceptable but not required).

submit 2030 test3C answers.txt