Problem 1

Below is code for a set of integers. A set can contain any number of integers. Operations for checking if a given integer is in the set, if the set is empty, adding an integer to the set, removing an integer from the set, and returning the smallest integer in the set are provided.
public class IntSet {
  private int[] elements;
  private int size;

  public IntSet() {
     elements = new int[2]; // allocate an array of integers
     size = 0;
  }

  public boolean contains(int element) {
     for (int i = 0; i < size; i++) {
        if (elements[i] == element) {
           return true;
        }
     }
     return false;
  }

  public boolean isEmpty() {
     return size == 0;
  }

  public void add(int element) {
     if (contains(element)) {
        return;
     }
     if (size == elements.length - 1) {
        increaseStore();
     }
     elements[size++] = element;
  }

  public void remove(int element) {
     for (int i = 0; i < size; i++) {
         if (elements[i] == element) {
            shift(i);
            size--;
         }
     }
  }

  public int getMin() {
     if (size == 0) {
        throw new RuntimeException("Cannot return the minimal element of an empty set");
     }
     int result = elements[0];
     for (int i = 1; i < size; i++) {
         if (result > elements[i]) {
            result = elements[i];
         }   
     }
     return result;
  }

  private void increaseStore() {
     int[] newElements = new int[elements.length * 2];
     for (int i = 0; i < size; i++) {
         newElements[i] = elements[i];
     }
     elements = newElements;
  }

  private void shift(int positionToRemove) {
     for (int i = positionToRemove; i < size - 1; i++) {
         elements[i] = elements[i + 1];
     }
  }

}

Give an EQN function for the ASTOOT method; it can be recursive or implementation-based.

Problem 2

Outline a strategy for unit-testing of the IntSet class from Problem 1. You don't have to use specifics of any testing frameworks. You don't even have to write actual code. Your strategy can simply be in the following format: "to test whether the contains method behaves correctly, I will populate an IntSet object with several integers and then check if the contains method determines that all these integers are in the set. I will also check that several integers that were not added to the set are not in the set."

Problem 3

Consider the following declarations of two classes A and B, where B is a subclass of A, and B overrides method g() of A.
class A {
	private int x;
	private int y;

	public A() {
		x = 3;
		y = -11;
	}

	public int f() {
		return x + 3;
	}

	public void g(int value) {
		x = value;
	}

	public void h(int value) {
		g(value);
		y = x * 2;
	}
}

class B extends A {
	public void g(int value) {
		x = value * 2;
	}
}

Problem 4

Consider the following simple method (you are right, it does not do anything useful):
	void method(int i, int j) {
		int k = i + 2 * j;
		int m;
		while (k > j) {
			if ((i > 2) && (j < 5)) {
				m = 1;
			}
			else {
				m = 0;
			}
			k--;
		}
	}