Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. public class IntSet 2. private Vector els; 3. //constructor 5. public IntSetO

ID: 3870673 • Letter: 1

Question

1. public class IntSet 2. private Vector els; 3. //constructor 5. public IntSetO 6. els = new Vector(); 8. 9. public void insert(int x) 10. I/Modifies: this 11. I/Effects: Adds x to the elements of this 12. 13. 14. public void remove(int x) 15. I/Modifies: this 16. l/Effects: removes x from this 17.3 18. public boolean isIn(int x)t 19. 20. 21. ircerer s If i in h ers take 22. private getIndex(Integer x) 23. 24.3 25 26. public int sizeO 27. I/Effects: returns the cardinality of this 28.) 29. 30. public int choose0 throws EmptyExcpetionf //Effects: if x is in this returns index where x appears else //returns-1 //Effects: if this is empty throws EmptyException else //returns an arbitrary element of this 32. 33. ) 34.

Explanation / Answer

Ans:

It's better use parameter constructor in this case,

public IntSet(Vector els){

this.els=els;

}

-->with this we will get Loose Coupling from this constructor. From Zero parameter Constructor we will get Tight Coupling.

-->As the name suggesting loose coupling means reducing dependencies of a class that use a different class directly. Loose coupling promotes greater reusability, easier maintainability. On the other hand tight coupling, classes and objects are dependent on one another.