EECS1030Z Test 1

Wednesday January 21, 2015, 14:30-15:00
Lab 02
Version D


/**
 * Test 1 utility class that provides fields and methods for working with
 * strings.
 * 
 */
public class TestD {

	/**
	 * The string equal to a single space " "
	 */
	public static final String SPACE = " ";

	/**
	 * The string equal to the tab character.
	 */
	public static final String TAB = "\t";

	/**
	 * Returns a new string formed by replacing each TestD.SPACE in s with
	 * TestD.TAB. Returns the empty string if s is null.
	 * 
	 * @param s
	 *            a string to search for spaces
	 * @return a new string with tabs replacing spaces in s, or
	 *         the empty string if s is null
	 * 
	 */
	public static String spacesToTabs(String s) {
		if (s == null) {
			return "";
		}
		return s.replaceAll(TestD.SPACE, TestD.TAB);
	}

	private TestD() {

	}
}


Multiple choice question

Question 1 Consider the following method header in the utility class Utility:
public static void someMethod(Complex c)

where Complex is the complex number class studied in the lectures. Suppose that a client invokes the method like so:

Complex y = new Complex(1, 2);
Complex z = new Complex(1, 2);
Utility.someMethod(z); 

Recall that Complex has a setReal method and a setImag method. Which of the following statements is correct after the client code has finished running?

A. y.equals(z) must be true
B. y.equals(z) must be false
C. y == z must be false
D. y == z might be true