EECS2030Z Test 2
Version C
GETTING STARTED
Start eclipse; use the workspace suggested by eclipse (or remember the
directory name of your workspace).
Import the test project by doing the following:
Under the File menu choose Import...
Under General choose Existing Projects into Workspace
and press Next
Click the Select archive file radio button, and click
the Browse... button.
Select the file test2C.zip and click OK
Click Finish .
All of the files you need for this test should now appear in eclipse.
Open a terminal. You will use this terminal to submit your work.
Copy and paste the command cd workspace/Test2C/src/test2
into
the terminal and press enter.
Question 1 (20 marks total)
Implement the utility
class described by this API .
You do not have to include javadoc comments.
submit 2030 test2C Utility2C.java
Question 2 (10 marks total)
Implement the constructors for the
class described by this API . Use constructor chaining where
possible when implementing your constructors.
You do not have to include javadoc comments in your code, but see Question 3C below.
submit 2030 test2C Fraction.java
Question 3 (20 marks total)
A.
State the definition of a method postcondition.
B.
Suppose that the method name areReversed
from Question 1 was implemented
like so:
public static boolean areReversed(String s, String t) {
boolean result;
/* code not shown here that assigns the correct value to result */
return result;
}
Suppose a client writes a main
method that includes the
following two lines of Java code:
String x = "xyz";
String y = "zyx";
boolean tf = Utility2C.areReversed(x, y);
The memory diagram illustrating the state of memory for the three lines of client code
is shown below.
What suitable values of a, b, and c would complete the memory diagram?
---------------------
| main method |
---------------------
x 100| 300a |
y 102| 400a |
tf 104| a? |
---------------------
| |
| |
---------------------
300| String object |
---------------------
| |
| |
---------------------
400| String object |
---------------------
| |
| |
---------------------
| areReversed |
---------------------
s 500| (not shown) |
t 502| b? |
result 504| c? |
---------------------
C.
Provide the Javadoc necessary to exactly reproduce the API documentation
for the constructor Range(int min, int max)
from
Question 2.
D.
Provide 3 test cases for the method Utility2C.areReversed
.
Make sure that each test case tests a different feature of the method;
try to include one boundary test case.
For each test case, provide a one sentence explanation of what the test case
is testing.
E.
Consider the following implementation of equals(Object)
for the class Range
from Question 2:
public class Range {
private int min;
private int max;
// constructors not shown
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
Range other = (Range) obj;
if (this.min - other.min == 0) {
return true;
}
if (this.max - other.max == 0) {
return true;
}
return false;
}
}
Explain whether or not the implementation shown above satisfies the equals
contract.
submit 2030 test2C answers.txt