Question: Question 2 (a) [8 marks] Recall that a class invariant (sometimes called an implementation invariant) is used to define which instance variable values are legal.

 Question 2 (a) [8 marks] Recall that a class invariant (sometimes

called an implementation invariant) is used to define which instance variable valuesare legal. Such a class invariant must be .established by the constructors

Question 2 (a) [8 marks] Recall that a class invariant (sometimes called an implementation invariant) is used to define which instance variable values are legal. Such a class invariant must be .established by the constructors of the class (i.e. when a constructor is invoked from a state satisfying its precondition, then it must be terminate in a state satisfying the class invariant). preserved by each of the methods of the class when they are called from states satisfying their preconditions (i.e. when these methods are invoked from a state that satisfies their precondition and the class invariant, then they will terminate in a state satisfying the class invariant.) . Provide a class invariant for the IntegerSet class that is strong enough to show that both methods size and get are correct with respect to their specifications in the IntegerSet class (i.e. when these methods are invoked from a state that satisfies their precondition and the class invariant, then they will terminate in a state satisfying their post-condition.) The class invariant can be expressed in a combination of English and Java notation. Question 2 (b) [4 marks] Provide a correct implementation of the following method remove for the IntegerSet class. The implementation of the whole class IntegerSet should remain correct after the addition of your remove-method implementation. (Your method should preserve the class invariant from the answer to part (a) of this question.) Removes an integer from the set *@ensure if x is contained in the set, then it is removed from the set, otherwise the set is unchanged by this operation. public void remove (Integer x) Question 2 (a) [8 marks] Recall that a class invariant (sometimes called an implementation invariant) is used to define which instance variable values are legal. Such a class invariant must be .established by the constructors of the class (i.e. when a constructor is invoked from a state satisfying its precondition, then it must be terminate in a state satisfying the class invariant). preserved by each of the methods of the class when they are called from states satisfying their preconditions (i.e. when these methods are invoked from a state that satisfies their precondition and the class invariant, then they will terminate in a state satisfying the class invariant.) . Provide a class invariant for the IntegerSet class that is strong enough to show that both methods size and get are correct with respect to their specifications in the IntegerSet class (i.e. when these methods are invoked from a state that satisfies their precondition and the class invariant, then they will terminate in a state satisfying their post-condition.) The class invariant can be expressed in a combination of English and Java notation. Question 2 (b) [4 marks] Provide a correct implementation of the following method remove for the IntegerSet class. The implementation of the whole class IntegerSet should remain correct after the addition of your remove-method implementation. (Your method should preserve the class invariant from the answer to part (a) of this question.) Removes an integer from the set *@ensure if x is contained in the set, then it is removed from the set, otherwise the set is unchanged by this operation. public void remove (Integer x)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!