EECS2030Z Test 3

Version D


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 test3D.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/Test3D/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 test3D CallLog.java


Question 2 (20 marks total)

A. (3 marks)

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

PhoneNumber n = PhoneNumber.getInstance(416, 736, 2100);
CallLogEntry e = new CallLogEntry(new Date(), n);

How many Date objects are created when running the client's code? Explain how you determined the number of Date objects.


B. (3 marks)

Suppose that you wanted to count the number of CallLogEntry objects created by a program.

(Part 1): What field would you need to add to the CallLogEntry class to keep track of the number of CallLogEntry objects created? Include the modifiers and type of the field in your answer.

(Part 2): Where in CallLogEntry would you update the value of the field that you added in (Part 1)?


C. (4 marks)

What is the difference between a shallow copy of a list and a deep copy of a list?


D. (5 marks) Suppose that CallLog had a getLog method that was implemented like so:
public List<CallLogEntry> getLog() {
    List<CallLogEntry> result;
    // code that makes result a shallow copy of this.log
    return result;
}
Suppose that a client writes the following code:
// assume that c is a CallLog with many entries
List<CallLogEntry> copy = c.getLog();

Assuming that getLog returns a shallow copy, show how the client can break the class invariant of CallLog. Explain why your answer breaks the class invariant.


E. (5 marks)

(Part 1): What two conditions are required to be true for compareTo to be consistent with equals?

(Part 2): Explain why the CallLogEntry implementation of compareTo is inconsistent with equals. One or two sentences should be sufficient for your answer.

submit 2030 test3D answers.txt