EECS2030Z Test 3

Version B


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 test3B.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/Test3B/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 test3B CellPhone.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:

CellPhone phone = new CellPhone(new CellNumber(416, 736, 2100));

How many CellNumber objects are created by the client's code? Explain how you determined the number of CellNumber objects.


B. (3 marks)

What is the definition of a singleton class?


C. (4 marks)

The API for the CellPhone method named getCallLog says that the method returns a shallow copy of the list of called cell numbers. What code would you write if the API had said that method returned a deep copy of the list of called numbers?


D. (5 marks)

(Part 1): Besides the fact that the call log is never equal to null, what class invariant does CellPhone have regarding its call log?

(Part 2): Explain why returning a shallow copy in getCallLog is sufficient to ensure that the invariant remains true (in other words, why is a deep copy of the call log not required?)


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 CellNumber implementation of compareTo is consistent with equals. One sentence should be sufficient for your answer.

submit 2030 test3B answers.txt