EECS1030M Test 1

Wednesday January 21, 2015, 16:00-16:30
Lab 01
Version F


/**
 * This utility class provides information about the height of the CN tower.
 * 
 * @author Franck van Breugel
 */
public class CNTower 
{
    private CNTower() {}
    
    /**
     * The height of the CN tower in meters.
     */
    public static final int HEIGHT = 553;
    
    /**
     * Returns the ratio of the given height and the 
     * height of the CN Tower.
     * 
     * @param height the height of a building in meters.
     * @pre. height >= 0
     * @return the given height divided by the height of the
     * CN tower.
     */
    public static double ratio(int height)
    {
	return height / (double) CNTower.HEIGHT;
    }
}


Multiple choice question

Question 1 Consider the following code snippet.
/**
 * This method does something.
 *
 * @param i an integer.
 * @pre. i >= 0
 */
public void method(int i)
{
   // method body left out
}

Which of the following statements is correct?

A. In the method body, the implementer has to throw an exception when i is smaller than zero.
B. In the method body, the implementer has to take the absolute value of i to ensure that its value is greater then or equal to zero.
C. In the method body, the implementer has to set i to zero whenever the value of i is smaller than zero.
D. None of the above.