EECS1030Z Test 1

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


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

	/**
	 * The empty string ""
	 */
	public static final String EMPTY = "";

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

	/**
	 * Return a string of length n where all of the characters in the string are
	 * equal to TestH.CHAR_SPACE
	 * 
	 * @param n
	 *            the length of the desired string
	 * @pre. n >= 0
	 * @return a string made up of TestH.CHAR_SPACE repeated n times
	 */
	public static String allSpaces(int n) {
		StringBuilder b = new StringBuilder();
		for (int i = 0; i < n; i++) {
			b.append(TestH.CHAR_SPACE);
		}
		return b.toString();
	}
	
	
	private TestH() {
		
	}

}


Multiple choice question

Question 1 Consider the following method documentation and header in the utility class Utility:
/**
 * This method does something.
 *
 * @pre. c must not be equal to (0 + 0i)
 *
 */
public static void someMethod(Complex c)

where Complex is the complex number class studied in the lectures. Suppose that a client invokes the method using an argument equal to (0 + 0i):

Utility.someMethod(new Complex(0, 0));
Which of the following statements is correct?

A. The implementer of someMethod must validate that c is not equal to (0 + 0i)
B. The compiler will report an error and will fail to compile the program
C. The program will fail with an exception when it is run
D. The program behavior is unspecified when it is run