EECS2030 Sample Test 3 Version B


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 ElasticBand class. 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 Elasticband.java):

submit 2030 test3B ElasticBand.java


Other questions

Question 1

Instead of accessing the attribute or field name using this.name, it is better to use this.getName(). Which of the following provides the best rationale?
A. It may avoid code duplication.
B. It may make it easier to modify the representation of the attribute name.
C. A and B.
D. Neither A nor B.



Question 2

The class Circle has an attribute or field named radius of type int. To implement the singleton design pattern, which of the following is most appropriate?
A. private static Map<Integer, Circle> instance;
B. private static List<Circle> instance;
C. private static Set<Circle> instance;
D. private static Circle instance;



Question 3

A non-static method is invoked on a(n)  



Question 4

Delegating from one constructor to another is known as  



Question 5

The class IP has an attribute named address of type String and implements the multiton design pattern. The mutator setAddress is private. If we make the mutator setAddress public, will the IP class still implement the multiton design pattern? Explain your answer.



Question 6

Consider the following class.

public class Person 
{
   private int age;

   /**
    * Initializes this person with the given age.
    *
    * @param age the age of this person.
    */
   public Person(int age)
   {
      this.age = age;
   }

   /**
    * Increments the age of this person.
    */
   public void increment()
   {
      this.age++;
   }
}
Is
//@ invariant this.age >= 0
a class invariant? Explain your answer.