EECS2030E Test 2F

Mon Oct 3, 2016, 14:00-15:20
LAB 01
Version F


Instructions

There is one programming question and three other questions.

Instructions for submitting your solutions are given in the question sections. You may submit as many times as you want; your most recent submission will be the one recorded.

You may leave the lab when you are finished with the test.


Programming question

Implement this API. You do not have to include javadoc comments.

Here is a main method that you can use to perform some simple testing of your code.

Submit your program using the following command in a terminal (make sure you are in the directory containing your file Test2F.java):

submit 2030 test2F Test2F.java


Other questions

Create a file named answers.txt for your answers to the following questions.

Question 1

What is the main purpose of a constructor?:

A. to allocate memory for the object being constructed
B. to validate the arguments passed by the client before constructing the object
C. to set the state of the object being constructed
D. to load the class into memory before constructing the object

Question 2

Suppose a client uses the Complex number class in a program like so:

Complex y = new Complex(1, 5);
Complex z = new Complex(1, 5);
???.setReal(???);                 // WHAT DID THE CLIENT WRITE ON THIS LINE?

A memory diagram is shown below for the moment when the setReal method body is about to run:

        100 |     client      |
     y      |  400            |
     z      |  500            |
            |                 |
            |                 |
        400 | Complex object  |
  real      |  1              |
  imag      |  5              |
            |                 |
            |                 |
        500 | Complex object  |
  real      |  1              |
  imag      |  5              |
            |                 |
            |                 |
        800 | Complex setReal |
  this      |  500            |
  real      |  10             |
            |                 |

What Java statement did the client write to invoke the setReal method (i.e., what did the client write on the line with the comment WHAT DID THE CLIENT WRITE ON THIS LINE??



Question 3

Inspect the API for the method Test2F.isBetween.

State three test cases that you would use to test the implementation of Test2F.isBetween and explain why you would include these test cases. Make sure that your test cases test different ways that the implementation might fail.



Submit your program using the following command in a terminal (make sure you are in the directory containing your file answers.txt):

submit 2030 test2F answers.txt