EECS1030Z Test 1

Thursday January 22, 2015, 14:30-15:00
Lab 02
Version G


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

	/**
	 * The char equal to a single space.
	 */
	public static final char CHAR_SPACE = ' ';

	/**
	 * Checks if a string s is made up of one or more TestG.CHAR_SPACE
	 * characters. Returns false if the string s is null.
	 * 
	 * @param s
	 *            a string to check
	 * @return true if every character of s is equal to TestG.CHAR_SPACE, false
	 *         otherwise.
	 */
	public static boolean isAllSpaces(String s) {
		if (s == null || s.isEmpty()) {
			return false;
		}
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) != TestG.CHAR_SPACE) {
				return false;
			}
		}
		return true;
	}

	private TestG() {

	}

}


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(3, 4);
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) might be true
B. y.equals(z) must be false
C. y == z must be true
D. y == z might be true