EECS2030E Test 1D

Tue Sep 27, 2016, 16:00-16:30
LAB 2
Version D


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 2.
 *
 * @author EECS2030E
 *
 */
public class Test1D {

    /**
     * The number of slices in a large pizza.
     */
    public final static int SLICES_LARGE = 10;

    private Test1D() {
        // empty by design
    }

    /**
     * Computes the total number of slices in the given
     * number of large pizzas. It is assumed that the
     * number of pizzas is greater than or equal to zero.
     *
     * @param n the number of large pizzas
     * @return the total number of slices
     */
    public static int numberOfSlices(int n) {
        return n * Test1D.SLICES_LARGE;
    }
}

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 public 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 Test1D.java file). Submit your answer using the following command:

submit 2030 test1D answers.txt