EECS2030 Sample Test 3


Instructions

There is one programming question and six other questions.

Instructions for submitting your programming question solution are given in the programming question section. You may submit as many times as you want; your most recent submission will be the one recorded.

You may leave the lab when you are finished with the test.


Programming question

Implement the Range class having the API shown here. A skeleton can be found here.

Submit your program using the following command in a terminal (make sure you are in the directory containing your file Range.java):

submit 2030 test3C Range.java


Other questions

Question 1

What is the purpose of a singleton class?

A. to prevent the client from directly creating an instance of the singleton type
B. to ensure that there is always exactly zero or one instance of the singleton type
C. to ensure that there is exactly one instance for every unique state of the singleton type
D. to replace a utility class with an instance of the singleton class

Question 2

The Range method named centeredAt resembles a constructor in that it returns a reference to a new Range object. Why can it not be a constructor in Range?

A. it does not specify a minimum and maximum value for the range
B. it has a precondition and constructors should not have preconditions
C. the client can use another constructor to achieve the same result
D. it has the same parameter list as another constructor

Question 3

The Range method named centeredAt resembles a constructor in that it returns a reference to a new Range object; what name is given to a method like centeredAt that returns a reference to a newly created object?

Type your answer here:

Question 4

What is the name of the relationship between the two classes shown in the following UML diagram:



Type your answer here:

Question 5

As the implementer of Range, list all of the changes that you would make to the Range class so that a client could obtain the number of Range objects that have been created in the client's application?



Question 6

Suppose that we modifed the Range class so that it implemented the interface Comparable<Range>. Consider the following implementation of the method compareTo:

public int compareTo(Range other) {
  if (this.overlaps(other)) {
    return 0;
  }
  if (this.getMaximum() < other.getMinimum()) {
    return -1;
  }
  return 1;
}

Explain whether or not the implementation of compareTo is reasonable.