EECS2030E Test 1C

Mon Sep 27, 2016, 14:00-14:30
LAB 1
Version C


Programming question

Implement this API. You do not have to include javadoc comments. If you do not know the value of the constant, just choose the value yourself.

package eecs2030.test1;

/**
 * Test 1 for EECS 2030E Lab 1.
 *
 * @author EECS2030E
 *
 */
public class Test1C {

    /**
     * The value 2π
     */
    public static final double TWO_PI = 2.0 * Math.PI;

    private Test1C() {
        // empty by design
    }

    /**
     * Returns the circumference of a circle having the given
     * radius. It is assumed that the radius is greater than
     * or equal to zero.
     *
     * <p>
     * The circumference of a circle having radius <i>r</i>
     * is equal to 2π<i>r</i>
     *
     * @param radius the radius of the circle
     * @return the circumference of the circle with the given radius
     */
    public static double circumference(double radius) {
        return Test1C.TWO_PI * radius;
    }

}

Multiple choice question

Question 1

Every utility class should have:

A. at least one non-static field
B. at least one non-static method
C. at most one static field
D. a private default constructor

Answer:
The answer is D. A utility class should have no constructors because we never need to make instances of the utility class. It should have a private default constructor because the Java compiler will insert a public default constructor if no constructors are defined in the class. By including our own private default constructor, we ensure that the compiler does not insert a public default constructor, and we ensure that no client can use the constructor to make instances of our class (because the constructor is private).

Save your file (it might be easiest to save the file in the same directory as your Test1C.java file). Submit your answer using the following command:

submit 2030 test1C answers.txt