CS/SWE 332 In Class Exercise Number 12

Name(s):
Topics: Inheritance, invariants, dispatching, abstract states
public class IntSet {
    public void insert(int x) {...; repOk();}
    public void remove(int x) {...; repOk();}
    public boolean repOk() {...}
}
public class MaxIntSet extends IntSet {
    private int biggest;  // the biggest element if the set is not empty

    public void insert(int x) {...; super.insert(x); repOk();}
    public void remove(int x) {super.remove(x); ...; repOk();}
    public boolean repOk() {super.repOk(); ...;}
    public int max() {  // return max value }
}
   MaxIntSet s = {3, 5}; s.remove(5); 
Analyze the repOk() calls.

Note: We did this part of the exercise as a group during the reading quiz review.

There are two logical choices for an abstract state for MaxIntSet. What are they, which one should you prefer, and why?

Would your answer change for a SortedIntSet class?